]> source.dussan.org Git - jquery.git/commitdiff
Update sizzle; Add sizzle cache collision iframe test. Fixes #8539.
authortimmywil <timmywillisn@gmail.com>
Thu, 13 Oct 2011 15:11:41 +0000 (11:11 -0400)
committertimmywil <timmywillisn@gmail.com>
Thu, 13 Oct 2011 15:11:41 +0000 (11:11 -0400)
src/sizzle
test/data/selector.html [deleted file]
test/data/selector/html5_selector.html [new file with mode: 0644]
test/data/selector/sizzle_cache.html [new file with mode: 0644]
test/unit/selector.js

index 3ffd629e38c3a1cc31febc010718c985a4f85a4d..f56f1784961a63f4118e43b1441ffc2f32ef5d41 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 3ffd629e38c3a1cc31febc010718c985a4f85a4d
+Subproject commit f56f1784961a63f4118e43b1441ffc2f32ef5d41
diff --git a/test/data/selector.html b/test/data/selector.html
deleted file mode 100644 (file)
index 8ffc6c6..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-<!doctype html>
-<html>
-<head>
-       <meta http-equiv="Content-type" content="text/html; charset=utf-8">
-       <title>jQuery selector</title>
-
-       <script src="../../src/core.js"></script>
-       <script src="../../src/callbacks.js"></script>
-       <script src="../../src/deferred.js"></script>
-       <script src="../../src/support.js"></script>
-       <script src="../../src/data.js"></script>
-       <script src="../../src/queue.js"></script>
-       <script src="../../src/attributes.js"></script>
-       <script src="../../src/event.js"></script>
-       <script src="../../src/sizzle/sizzle.js"></script>
-       <script src="../../src/sizzle-jquery.js"></script>
-       <script src="../../src/traversing.js"></script>
-       <script src="../../src/manipulation.js"></script>
-       <script src="../../src/css.js"></script>
-       <script src="../../src/ajax.js"></script>
-       <script src="../../src/ajax/jsonp.js"></script>
-       <script src="../../src/ajax/script.js"></script>
-       <script src="../../src/ajax/xhr.js"></script>
-       <script src="../../src/effects.js"></script>
-       <script src="../../src/offset.js"></script>
-       <script src="../../src/dimensions.js"></script>
-
-       <script id="script1"
-                       defer
-                       async></script>
-
-       <script type="text/javascript">
-               document.createElement('video');
-               document.createElement('audio');
-               document.createElement('article');
-               document.createElement('details');
-       </script>
-</head>
-<body>
-       <img id="img1"
-                ismap>
-
-       <hr id="hr1"
-               noshade>
-
-       <form id="form1"
-                 name="formName"
-                 novalidate
-                 formnovalidate>
-               <input type="text" id="text1"
-                          tabindex="1"
-                          name="name"
-                          required
-                          autofocus
-                          readonly>
-               <textarea id="textarea1"
-                                 noresize></textarea>
-       </form>
-
-       <table>
-               <tr><td id="td1"
-                               nowrap></td></tr>
-       </table>
-
-       <iframe id="iframe1"
-                       src="iframe.html"
-                       seamless></iframe>
-
-       <style id="style1"
-                  scoped></style>
-
-       <ol id="ol1"
-               reversed></ol>
-
-       <article id="article1"
-                        pubdate></article>
-
-       <details id="details1"
-                        open></details>
-
-       <div id="div1"
-                nowrap
-                hidden
-                itemscope
-                draggable="true"
-                contenteditable="true"
-                aria-disabled="true">
-               <p>My name is <span id="span1"
-                                                       spellcheck="true"
-                                                       itemprop="name">Elizabeth</span>.</p>
-       </div>
-
-       <audio id="audio1"
-                  muted></audio>
-
-       <video id="video1"
-                  loop
-                  controls
-                  autoplay
-                  autobuffer></video>
-
-       <map id="map1">
-               <area id="area1"
-                         nohref
-                         shape="default">
-       </map>
-
-       <input id="check1"
-                  type="checkbox"
-                  disabled
-                  checked>
-
-       <select id="select1"
-                       multiple>
-               <option id="option1"
-                               selected
-                               value="blar">blar</option>
-       </select>
-
-       <dl id="dl"
-               compact>
-               <dt>Term</dt><dd>This is the first definition in compact format.</dd>
-               <dt>Term</dt><dd>This is the second definition in compact format.</dd>
-       </dl>
-
-       <object id="object1"
-                       declare></object>
-
-       <marquee id="marquee1"
-                        direction="up"
-                        truespeed>Scrolling text (non-standard)</marquee>
-</body>
-</html>
diff --git a/test/data/selector/html5_selector.html b/test/data/selector/html5_selector.html
new file mode 100644 (file)
index 0000000..28aa2b6
--- /dev/null
@@ -0,0 +1,133 @@
+<!doctype html>
+<html>
+<head>
+       <meta http-equiv="Content-type" content="text/html; charset=utf-8">
+       <title>jQuery selector - attributes</title>
+
+       <script src="../../../src/core.js"></script>
+       <script src="../../../src/callbacks.js"></script>
+       <script src="../../../src/deferred.js"></script>
+       <script src="../../../src/support.js"></script>
+       <script src="../../../src/data.js"></script>
+       <script src="../../../src/queue.js"></script>
+       <script src="../../../src/attributes.js"></script>
+       <script src="../../../src/event.js"></script>
+       <script src="../../../src/sizzle/sizzle.js"></script>
+       <script src="../../../src/sizzle-jquery.js"></script>
+       <script src="../../../src/traversing.js"></script>
+       <script src="../../../src/manipulation.js"></script>
+       <script src="../../../src/css.js"></script>
+       <script src="../../../src/ajax.js"></script>
+       <script src="../../../src/ajax/jsonp.js"></script>
+       <script src="../../../src/ajax/script.js"></script>
+       <script src="../../../src/ajax/xhr.js"></script>
+       <script src="../../../src/effects.js"></script>
+       <script src="../../../src/offset.js"></script>
+       <script src="../../../src/dimensions.js"></script>
+
+       <script id="script1"
+                       defer
+                       async></script>
+
+       <script type="text/javascript">
+               document.createElement('video');
+               document.createElement('audio');
+               document.createElement('article');
+               document.createElement('details');
+       </script>
+</head>
+<body>
+       <img id="img1"
+                ismap>
+
+       <hr id="hr1"
+               noshade>
+
+       <form id="form1"
+                 name="formName"
+                 novalidate
+                 formnovalidate>
+               <input type="text" id="text1"
+                          tabindex="1"
+                          name="name"
+                          required
+                          autofocus
+                          readonly>
+               <textarea id="textarea1"
+                                 noresize></textarea>
+       </form>
+
+       <table>
+               <tr><td id="td1"
+                               nowrap></td></tr>
+       </table>
+
+       <iframe id="iframe1"
+                       src="iframe.html"
+                       seamless></iframe>
+
+       <style id="style1"
+                  scoped></style>
+
+       <ol id="ol1"
+               reversed></ol>
+
+       <article id="article1"
+                        pubdate></article>
+
+       <details id="details1"
+                        open></details>
+
+       <div id="div1"
+                nowrap
+                hidden
+                itemscope
+                draggable="true"
+                contenteditable="true"
+                aria-disabled="true">
+               <p>My name is <span id="span1"
+                                                       spellcheck="true"
+                                                       itemprop="name">Elizabeth</span>.</p>
+       </div>
+
+       <audio id="audio1"
+                  muted></audio>
+
+       <video id="video1"
+                  loop
+                  controls
+                  autoplay
+                  autobuffer></video>
+
+       <map id="map1">
+               <area id="area1"
+                         nohref
+                         shape="default">
+       </map>
+
+       <input id="check1"
+                  type="checkbox"
+                  disabled
+                  checked>
+
+       <select id="select1"
+                       multiple>
+               <option id="option1"
+                               selected
+                               value="blar">blar</option>
+       </select>
+
+       <dl id="dl"
+               compact>
+               <dt>Term</dt><dd>This is the first definition in compact format.</dd>
+               <dt>Term</dt><dd>This is the second definition in compact format.</dd>
+       </dl>
+
+       <object id="object1"
+                       declare></object>
+
+       <marquee id="marquee1"
+                        direction="up"
+                        truespeed>Scrolling text (non-standard)</marquee>
+</body>
+</html>
diff --git a/test/data/selector/sizzle_cache.html b/test/data/selector/sizzle_cache.html
new file mode 100644 (file)
index 0000000..de1a583
--- /dev/null
@@ -0,0 +1,40 @@
+<!doctype html>
+<html>
+<head>
+       <meta http-equiv="Content-type" content="text/html; charset=utf-8">
+       <title>jQuery selector - sizzle cache</title>
+
+       <script src="http://code.jquery.com/jquery-git.js"></script>
+       <script>
+               var $git = jQuery.noConflict(true);
+       </script>
+       <script src="../../../src/core.js"></script>
+       <script src="../../../src/callbacks.js"></script>
+       <script src="../../../src/deferred.js"></script>
+       <script src="../../../src/support.js"></script>
+       <script src="../../../src/data.js"></script>
+       <script src="../../../src/queue.js"></script>
+       <script src="../../../src/attributes.js"></script>
+       <script src="../../../src/event.js"></script>
+       <script src="../../../src/sizzle/sizzle.js"></script>
+       <script src="../../../src/sizzle-jquery.js"></script>
+       <script src="../../../src/traversing.js"></script>
+       <script src="../../../src/manipulation.js"></script>
+       <script src="../../../src/css.js"></script>
+       <script src="../../../src/ajax.js"></script>
+       <script src="../../../src/ajax/jsonp.js"></script>
+       <script src="../../../src/ajax/script.js"></script>
+       <script src="../../../src/ajax/xhr.js"></script>
+       <script src="../../../src/effects.js"></script>
+       <script src="../../../src/offset.js"></script>
+       <script src="../../../src/dimensions.js"></script>
+
+</head>
+<body>
+
+       <div class="test">
+               <a href="#" id="collision">Worlds collide</a>
+       </div>
+
+</body>
+</html>
index 441258008ad27ac69611513beea161f0462c66a0..2c9dcec830f091b76f81873374ff5392074ebc60 100644 (file)
@@ -17,7 +17,7 @@ var testIframe = function( fileName, name, fn ) {
        var loadFixture = function() {
 
                // Creates iframe with cache disabled
-               var src = "./data/" + fileName + ".html?" + parseInt( Math.random()*1000, 10 ),
+               var src = "./data/selector/" + fileName + ".html?" + parseInt( Math.random()*1000, 10 ),
                        iframe = jQuery("<iframe />").css({
                                width: 500, height: 500, position: "absolute", top: -600, left: -600, visibility: "hidden"
                        }).appendTo("body")[0];
@@ -38,7 +38,7 @@ var testIframe = function( fileName, name, fn ) {
                                        // continue
                                        start();
                                        // call actual tests passing the correct jQuery instance to use
-                                       fn.call( this, win.jQuery, win );
+                                       fn.call( this, win.jQuery, win, win.document );
                                        document.body.removeChild( iframe );
                                        iframe = null;
                                }
@@ -46,23 +46,21 @@ var testIframe = function( fileName, name, fn ) {
        });
 };
 
-testIframe("selector", "attributes - jQuery.attr", function( jQuery, window ) {
+testIframe("html5_selector", "attributes - jQuery.attr", function( jQuery, window, document ) {
        expect(34);
 
-       var document = window.document;
-
        /**
         * Returns an array of elements with the given IDs, eg.
         */
-       var q = function() {
-               var r = [];
-        
-               for ( var i = 0; i < arguments.length; i++ ) {
-                       r.push( document.getElementById( arguments[i] ) );
-               }
-        
-               return r;
-       };
+       function q() {
+               var r = [],
+                       i = 0;
+
+               for ( ; i < arguments.length; i++ ) {
+                       r.push( document.getElementById( arguments[i] ) );
+               }
+               return r;
+       }
                           
        /**
         * Asserts that a select matches the given IDs * @example t("Check for something", "//[a]", ["foo", "baar"]);
@@ -70,15 +68,17 @@ testIframe("selector", "attributes - jQuery.attr", function( jQuery, window ) {
         * @param {String} b - Sizzle selector
         * @param {String} c - Array of ids to construct what is expected
         */
-       var t = function( a, b, c ) {
-               var f = jQuery(b).get(), s = "";
+       function t( a, b, c ) {
+               var f = jQuery(b).get(),
+                       s = "",
+                       i = 0;
                
-               for ( var i = 0; i < f.length; i++ ) {
-                       s += (s && ",") + '"' + f[i].id + '"';
+               for ( ; i < f.length; i++ ) {
+                       s += (s && ",") + '"' + f[i].id + '"';
                }
 
                deepEqual(f, q.apply( q, c ), a + " (" + b + ")");
-       };
+       }
 
        // ====== All known boolean attributes, including html5 booleans ======
        // autobuffer, autofocus, autoplay, async, checked,
@@ -131,3 +131,12 @@ testIframe("selector", "attributes - jQuery.attr", function( jQuery, window ) {
 
        t( "Improperly named form elements do not interfere with form selections (#9570)", "form[name='formName']", ["form1"]);
 });
+
+testIframe("sizzle_cache", "Sizzle cache collides with multiple Sizzles on a page", function( jQuery, window, document ) {
+       var $git = window.$git;
+
+       expect(3);
+       deepEqual( $git('.test a').get(), [ document.getElementById('collision') ], "Select collision anchor with first sizzle" );
+       equal( jQuery('.evil a').length, 0, "Select nothing with second sizzle" );
+       equal( jQuery('.evil a').length, 0, "Select nothing again with second sizzle" );
+});