aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Waldron <waldron.rick@gmail.com>2011-04-30 10:42:36 -0400
committerRick Waldron <waldron.rick@gmail.com>2011-04-30 10:42:36 -0400
commit0c2d1aee5421b650159116b6bdcb74a4fe96f9ad (patch)
tree60bb60334b60cbae60cc5abe7410f9b74f016d29
parente2bace8fa129c2bf3fe5bd382a4b05d96e8cf245 (diff)
downloadjquery-0c2d1aee5421b650159116b6bdcb74a4fe96f9ad.tar.gz
jquery-0c2d1aee5421b650159116b6bdcb74a4fe96f9ad.zip
jQuery.buildFragment, ensure doc is a document; Includes comments; Adds unit test. Fixes #8950
-rw-r--r--src/manipulation.js21
-rw-r--r--test/unit/manipulation.js11
2 files changed, 27 insertions, 5 deletions
diff --git a/src/manipulation.js b/src/manipulation.js
index 610d19b7a..aeea083a9 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -437,8 +437,21 @@ function cloneFixAttributes( src, dest ) {
}
jQuery.buildFragment = function( args, nodes, scripts ) {
- var fragment, cacheable, cacheresults,
- doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document);
+ var fragment, cacheable, cacheresults, doc;
+
+ // nodes may contain either an explicit document object,
+ // a jQuery collection or context object.
+ // If nodes[0] contains a valid object to assign to doc
+ if ( nodes && nodes[0] ) {
+ doc = nodes[0].ownerDocument || nodes[0];
+ }
+
+ // Ensure that an attr object doesn't incorrectly stand in as a document object
+ // Chrome and Firefox seem to allow this to occur and will throw exception
+ // Fixes #8950
+ if ( !doc.createDocumentFragment ) {
+ doc = document;
+ }
// Only cache "small" (1/2 KB) HTML strings that are associated with the main document
// Cloning options loses the selected state, so don't cache them
@@ -500,7 +513,7 @@ jQuery.each({
function getAll( elem ) {
if ( "getElementsByTagName" in elem ) {
return elem.getElementsByTagName( "*" );
-
+
} else if ( "querySelectorAll" in elem ) {
return elem.querySelectorAll( "*" );
@@ -746,4 +759,4 @@ function evalScript( i, elem ) {
}
}
-})( jQuery );
+})( jQuery ); \ No newline at end of file
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index b71b6962e..a2b5c2e59 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -1382,6 +1382,15 @@ test("jQuery.buildFragment - no plain-text caching (Bug #6779)", function() {
}
catch(e) {}
}
- equals($f.text(), bad.join(""), "Cached strings that match Object properties");
+ equals($f.text(), bad.join(""), "Cached strings that match Object properties");
$f.remove();
});
+
+test("jQuery.buildFragment - plain objects are not a document #8950", function() {
+ expect(1);
+
+ try {
+ jQuery('<input type="hidden">', {});
+ ok( true, "Does not allow attribute object to be treated like a doc object");
+ } catch (e) {}
+});