aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Gibson <richard.gibson@gmail.com>2013-09-18 09:41:07 -0400
committerRichard Gibson <richard.gibson@gmail.com>2013-11-07 11:37:52 -0500
commit126d596b56924613687329b7aab4f0cdf4b593b3 (patch)
treedc919662b389ba3e1acca9b46fde33a9e4b0ce2d
parentd0b8f9fa932be3d95728a881ec63c7231887de0a (diff)
downloadjquery-126d596b56924613687329b7aab4f0cdf4b593b3.tar.gz
jquery-126d596b56924613687329b7aab4f0cdf4b593b3.zip
Fix #14074: element id="nodeName". Close gh-1389.
-rw-r--r--src/data.js12
-rw-r--r--src/data/accepts.js14
-rw-r--r--test/data/core/aliased.html24
-rw-r--r--test/unit/core.js7
-rw-r--r--test/unit/data.js22
5 files changed, 57 insertions, 22 deletions
diff --git a/src/data.js b/src/data.js
index 8b4b0efca..256bed7cd 100644
--- a/src/data.js
+++ b/src/data.js
@@ -238,13 +238,13 @@ function internalRemoveData( elem, name, pvt ) {
jQuery.extend({
cache: {},
- // The following elements throw uncatchable exceptions if you
- // attempt to add expando properties to them.
+ // The following elements (space-suffixed to avoid Object.prototype collisions)
+ // throw uncatchable exceptions if you attempt to set expando properties
noData: {
- "applet": true,
- "embed": true,
- // Ban all objects except for Flash (which handle expandos)
- "object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
+ "applet ": true,
+ "embed ": true,
+ // ...but Flash objects (which have this classid) *can* handle expandos
+ "object ": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
},
hasData: function( elem ) {
diff --git a/src/data/accepts.js b/src/data/accepts.js
index 28ef23a01..6e0b1b518 100644
--- a/src/data/accepts.js
+++ b/src/data/accepts.js
@@ -6,15 +6,15 @@ define([
* Determines whether an object can have data
*/
jQuery.acceptData = function( elem ) {
- // Do not set data on non-element because it will not be cleared (#8335).
- if ( elem.nodeType && elem.nodeType !== 1 && elem.nodeType !== 9 ) {
- return false;
- }
+ var noData = jQuery.noData[ (elem.nodeName + " ").toLowerCase() ],
+ nodeType = +elem.nodeType || 1;
- var noData = elem.nodeName && jQuery.noData[ elem.nodeName.toLowerCase() ];
+ // Do not set data on non-element DOM nodes because it will not be cleared (#8335).
+ return nodeType !== 1 && nodeType !== 9 ?
+ false :
- // nodes accept data unless otherwise specified; rejection can be conditional
- return !noData || noData !== true && elem.getAttribute("classid") === noData;
+ // Nodes accept data unless otherwise specified; rejection can be conditional
+ !noData || noData !== true && elem.getAttribute("classid") === noData;
};
return jQuery.acceptData;
diff --git a/test/data/core/aliased.html b/test/data/core/aliased.html
new file mode 100644
index 000000000..ed06606af
--- /dev/null
+++ b/test/data/core/aliased.html
@@ -0,0 +1,24 @@
+<!doctype html>
+<html>
+<head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
+ <title>alias-masked DOM properties (#14074)</title>
+ <script>
+ var errors = [];
+ window.onerror = function( errorMessage, filePath, lineNumber ) {
+ errors.push( errorMessage );
+ };
+ </script>
+ <script src="../../jquery.js"></script>
+</head>
+<body>
+ <form>
+ <input type="text" id="nodeName"/>
+ </form>
+ <script>
+ jQuery(function() {
+ window.parent.iframeCallback( errors );
+ });
+ </script>
+</body>
+</html>
diff --git a/test/unit/core.js b/test/unit/core.js
index 6e4de4864..5cfb136a1 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -1419,3 +1419,10 @@ testIframeWithCallback( "Conditional compilation compatibility (#13274)", "core/
deepEqual( errors, [], "No errors" );
ok( $(), "jQuery executes" );
});
+
+testIframeWithCallback( "Tolerating alias-masked DOM properties (#14074)", "core/aliased.html",
+ function( errors ) {
+ expect( 1 );
+ deepEqual( errors, [], "jQuery loaded" );
+ }
+);
diff --git a/test/unit/data.js b/test/unit/data.js
index c62dcf952..6aace8a20 100644
--- a/test/unit/data.js
+++ b/test/unit/data.js
@@ -142,26 +142,30 @@ test("Data is not being set on comment and text nodes", function() {
});
test("jQuery.acceptData", function() {
- expect(9);
+ expect( 10 );
var flash, applet;
ok( jQuery.acceptData( document ), "document" );
ok( jQuery.acceptData( document.documentElement ), "documentElement" );
ok( jQuery.acceptData( {} ), "object" );
- ok( !jQuery.acceptData( document.createElement("embed") ), "embed" );
- ok( !jQuery.acceptData( document.createElement("applet") ), "applet" );
+ ok( !jQuery.acceptData( document.createElement( "embed" ) ), "embed" );
+ ok( !jQuery.acceptData( document.createElement( "applet" ) ), "applet" );
- flash = document.createElement("object");
- flash.setAttribute("classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000");
+ flash = document.createElement( "object" );
+ flash.setAttribute( "classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" );
ok( jQuery.acceptData( flash ), "flash" );
- applet = document.createElement("object");
- applet.setAttribute("classid", "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93");
+ applet = document.createElement( "object" );
+ applet.setAttribute( "classid", "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" );
ok( !jQuery.acceptData( applet ), "applet" );
- ok( !jQuery.acceptData( document.createComment("") ), "comment" );
- ok( !jQuery.acceptData( document.createTextNode("") ), "text" );
+ ok( !jQuery.acceptData( document.createComment( "" ) ), "comment" );
+ ok( !jQuery.acceptData( document.createTextNode( "" ) ), "text" );
+
+ ok( jQuery.acceptData(
+ jQuery( "#form" ).append( "<input id='nodeType'/><input id='nodeName'/>" )[ 0 ] ),
+ "form with aliased DOM properties" );
});
// attempting to access the data of an undefined jQuery element should be undefined