Test escaping HTML fix #50

pull/58/merge
Maciej Winnicki 2015-09-16 23:54:14 +02:00
parent 3879a6eb79
commit 054eb70c46
3 changed files with 11 additions and 13 deletions

View File

@ -182,18 +182,9 @@ window.App = (function (window, document) {
* @private
*/
var _escape = function (text) {
var entityMap = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
'\'': '&#39;',
'/': '&#x2F;'
};
return String(text).replace(/[&<>"'\/]/g, function (s) {
return entityMap[s];
});
var div = document.createElement('div');
div.appendChild(document.createTextNode(text));
return div.innerHTML;
};
return {

View File

@ -19,7 +19,7 @@
"jscs": "^1.6.2",
"jsdom": "^3.1.0",
"jshint": "~2.3.0",
"mocha": "~2.2.0",
"mocha": "~2.3.2",
"should": "~3.3.2",
"sinon": "~1.7.3",
"supertest": "~0.8.1",

View File

@ -98,6 +98,13 @@ describe('browser application', function () {
);
});
it('should escape HTML', function () {
io.emit('line', '<a/>');
var line = window.document.querySelector('.line');
line.innerHTML.should.equal('<p class="inner-line">&lt;a/&gt;</p>');
});
function initApp() {
window.App.init({
socket: io,