Skip to content

Commit

Permalink
Make sure that XHTML-style HTML is purified in .html(). Fixes #5845.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeresig committed Jan 25, 2010
1 parent f06e0e5 commit 6a3d099
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/manipulation.js
Expand Up @@ -189,6 +189,8 @@ jQuery.fn.extend({
(jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) &&
!wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) {

value = value.replace(rxhtmlTag, fcloseTag);

try {
for ( var i = 0, l = this.length; i < l; i++ ) {
// Remove element nodes and prevent memory leaks
Expand Down Expand Up @@ -501,4 +503,4 @@ jQuery.extend({
jQuery.removeData( elem );
}
}
});
});
9 changes: 7 additions & 2 deletions test/unit/manipulation.js
Expand Up @@ -793,7 +793,7 @@ test("clone() on XML nodes", function() {
}

var testHtml = function(valueObj) {
expect(22);
expect(24);

jQuery.scriptorder = 0;

Expand All @@ -805,6 +805,11 @@ var testHtml = function(valueObj) {
}
ok( pass, "Set HTML" );

div = jQuery("<div/>").html( valueObj('<div id="parent_1"><div id="child_1"/></div><div id="parent_2"/>') );

equals( div.children().length, 2, "Make sure two child nodes exist." );
equals( div.children().children().length, 1, "Make sure that a grandchild exists." );

reset();
// using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents();
Expand Down Expand Up @@ -1040,4 +1045,4 @@ test("jQuery.cleanData", function() {

return div;
}
});
});

0 comments on commit 6a3d099

Please sign in to comment.