Skip to content

Commit d638aa9

Browse files
committed
Allow more cases to use innerHTML in the .html method.
Thanks @cmcnulty for the pull and the patience!
2 parents a4cdbf0 + 2746d7f commit d638aa9

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/manipulation.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
66
rtagName = /<([\w:]+)/,
77
rtbody = /<tbody/i,
88
rhtml = /<|&#?\w+;/,
9+
rnoInnerhtml = /<(?:script|style)/i,
910
rnocache = /<(?:script|object|embed|option|style)/i,
1011
// checked="checked" or checked
1112
rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
@@ -217,7 +218,7 @@ jQuery.fn.extend({
217218
null;
218219

219220
// See if we can take a shortcut and just use innerHTML
220-
} else if ( typeof value === "string" && !rnocache.test( value ) &&
221+
} else if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
221222
(jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) &&
222223
!wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) {
223224

test/unit/manipulation.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ test("clone() (#8070)", function () {
991991
});
992992

993993
test("clone()", function() {
994-
expect(37);
994+
expect(40);
995995
equals( "This is a normal link: Yahoo", jQuery("#en").text(), "Assert text for #en" );
996996
var clone = jQuery("#yahoo").clone();
997997
equals( "Try them out:Yahoo", jQuery("#first").append(clone).text(), "Check for clone" );
@@ -1058,6 +1058,14 @@ test("clone()", function() {
10581058
cloneEvt.remove();
10591059
divEvt.remove();
10601060

1061+
// Test both html() and clone() for <embed and <object types
1062+
div = jQuery("<div/>").html('<embed height="355" width="425" src="http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en"></embed>');
1063+
1064+
clone = div.clone(true);
1065+
equals( clone.length, 1, "One element cloned" );
1066+
equals( clone.html(), div.html(), "Element contents cloned" );
1067+
equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
1068+
10611069
// this is technically an invalid object, but because of the special
10621070
// classid instantiation it is the only kind that IE has trouble with,
10631071
// so let's test with it too.

0 commit comments

Comments
 (0)