Skip to content

Commit

Permalink
Land: content of script tags should not be escaped (Ken Sternberg)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpvar committed Nov 20, 2011
2 parents 44b545a + 81668f5 commit 9fa499d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/jsdom/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,17 @@ var browserAugmentation = exports.browserAugmentation = function(dom, options) {
});

dom.Element.prototype.__defineGetter__('innerHTML', function() {

if (this._tagName === 'script' &&
this._attributes.length > 0 &&
typeof(this._attributes._nodes.type) !== "undefined" &&
this._attributes._nodes.type._nodeValue.indexOf("text") === 0) {
return domToHtml(this._childNodes, true, true);
}

return domToHtml(this._childNodes, true);
});

dom.Element.prototype.__defineSetter__('doctype', function() {
throw new core.DOMException(NO_MODIFICATION_ALLOWED_ERR);
});
Expand Down
15 changes: 15 additions & 0 deletions test/jsdom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,21 @@ document.write("<SCR"+"IPT TYPE=\'text/javascript\' SRC=\'...\'><\/SCR"+"IPT>");
test.done();
},

issue_58_parse_templatedtags: function(test) {
/* There is a unit of whitespace at the front of the script tag
content as a workaround for
https://github.com/tautologistics/node-htmlparser/issues/29
*/
var content = ' <%= cid %>'
var script = '<script type="text/x-underscore-tmpl">' + content + '</script>'
var html = '<html><head>' + script + '</head><body><p>hello world!</p></body></html>'
console.log(html);
var doc = jsdom.html(html)
doc.innerHTML = html;
test.equal(doc.head.childNodes[0].innerHTML, content);
test.done();
},

issue_239_replace_causes_script_execution : function(test) {
jsdom.env({
html : '<script type="text/javascript">window.a = 1;/* remove me */ console.log("executed?")</script>',
Expand Down

0 comments on commit 9fa499d

Please sign in to comment.