Make sure that XHTML-style HTML is purified in .html(). Fixes #5845.

This commit is contained in:
John Resig 2010-01-24 21:37:05 -05:00
parent f06e0e5575
commit 6a3d0996ed
2 changed files with 10 additions and 3 deletions

View file

@ -189,6 +189,8 @@ jQuery.fn.extend({
(jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) && (jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) &&
!wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) { !wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) {
value = value.replace(rxhtmlTag, fcloseTag);
try { try {
for ( var i = 0, l = this.length; i < l; i++ ) { for ( var i = 0, l = this.length; i < l; i++ ) {
// Remove element nodes and prevent memory leaks // Remove element nodes and prevent memory leaks

View file

@ -793,7 +793,7 @@ test("clone() on XML nodes", function() {
} }
var testHtml = function(valueObj) { var testHtml = function(valueObj) {
expect(22); expect(24);
jQuery.scriptorder = 0; jQuery.scriptorder = 0;
@ -805,6 +805,11 @@ var testHtml = function(valueObj) {
} }
ok( pass, "Set HTML" ); 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(); reset();
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();