Skip to content

Commit

Permalink
Test escaping HTML fix #50
Browse files Browse the repository at this point in the history
  • Loading branch information
mthenw committed Sep 16, 2015
1 parent 3879a6e commit 054eb70
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
15 changes: 3 additions & 12 deletions lib/web/assets/app.js
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions test/app.js
Expand Up @@ -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,
Expand Down

0 comments on commit 054eb70

Please sign in to comment.