]> source.dussan.org Git - jquery.git/commitdiff
Core: re-introduce createHTMLDocument in parseHTML; Safari 8 left out
authorTimmy Willison <timmywillisn@gmail.com>
Wed, 10 Dec 2014 14:48:55 +0000 (09:48 -0500)
committerTimmy Willison <timmywillisn@gmail.com>
Wed, 10 Dec 2014 14:51:30 +0000 (09:51 -0500)
Close gh-1505

src/core/parseHTML.js
src/core/support.js [new file with mode: 0644]
test/data/testinit.js
test/unit/core.js
test/unit/support.js

index e0348971dcb887adb76a6e7acad085047f2ec7c6..2b638e6331b9b6fde5d1f5b84fdef36971a32c4c 100644 (file)
@@ -2,8 +2,12 @@ define([
        "../core",
        "./var/rsingleTag",
 
-       "../manipulation" // buildFragment
-], function( jQuery, rsingleTag ) {
+       // This is the only module that needs core/support
+       "./support",
+
+       // buildFragment
+       "../manipulation"
+], function( jQuery, rsingleTag, support ) {
 
 // data: string of html
 // context (optional): If specified, the fragment will be created in this context,
@@ -17,7 +21,11 @@ jQuery.parseHTML = function( data, context, keepScripts ) {
                keepScripts = context;
                context = false;
        }
-       context = context || document;
+       // document.implementation stops scripts or inline event handlers from
+       // being executed immediately
+       context = context || ( support.createHTMLDocument ?
+               document.implementation.createHTMLDocument( "" ) :
+               document );
 
        var parsed = rsingleTag.exec( data ),
                scripts = !keepScripts && [];
diff --git a/src/core/support.js b/src/core/support.js
new file mode 100644 (file)
index 0000000..ebed460
--- /dev/null
@@ -0,0 +1,12 @@
+define([
+       "../var/support"
+], function( support ) {
+
+support.createHTMLDocument = (function() {
+       var doc = document.implementation.createHTMLDocument( "" );
+       doc.body.innerHTML = "<form></form><form></form>";
+       return doc.body.childNodes.length === 2;
+})();
+
+return support;
+});
index 9b3caba937571ce6edd10341d618f2ffeb4fc85c..468956d4dfb30c5e2b85e38875778d6a3818cab0 100644 (file)
@@ -301,7 +301,7 @@ this.loadTests = function() {
                                /**
                                 * Run in noConflict mode
                                 */
-                               if (jQuery.noConflict) {
+                               if ( jQuery.noConflict ) {
                                        jQuery.noConflict();
                                }
 
index 17006a8ab5ac381cb079b978c36d8eeebe51fa7e..034473b5c9b100ad15ce32245c6120987683e4b1 100644 (file)
@@ -235,7 +235,7 @@ test( "globalEval execution after script injection (#7862)", 1, function() {
 });
 
 // This is not run in AMD mode
-if (jQuery.noConflict) {
+if ( jQuery.noConflict ) {
        test("noConflict", function() {
                expect(7);
 
@@ -1370,6 +1370,22 @@ test("jQuery.parseHTML", function() {
        ok( jQuery.parseHTML("<#if><tr><p>This is a test.</p></tr><#/if>") || true, "Garbage input should not cause error" );
 });
 
+if ( jQuery.support.createHTMLDocument ) {
+       asyncTest("jQuery.parseHTML", function() {
+               expect ( 1 );
+
+               Globals.register("parseHTMLError");
+
+               jQuery.globalEval("parseHTMLError = false;");
+               jQuery.parseHTML( "<img src=x onerror='parseHTMLError = true'>" );
+
+               window.setTimeout(function() {
+                       start();
+                       equal( window.parseHTMLError, false, "onerror eventhandler has not been called." );
+               }, 2000);
+       });
+}
+
 test("jQuery.parseJSON", function() {
        expect( 20 );
 
index 11f15a33b4ce87dc39bb5a45ca862060322308ae..0e58aa53b4ee73f4a2ddf0a3aadc79f1b79c0cd5 100644 (file)
@@ -61,6 +61,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "checkOn": true,
                        "clearCloneStyle": true,
                        "cors": true,
+                       "createHTMLDocument": true,
                        "focusinBubbles": false,
                        "noCloneChecked": true,
                        "optDisabled": true,
@@ -77,6 +78,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "checkOn": true,
                        "clearCloneStyle": false,
                        "cors": true,
+                       "createHTMLDocument": true,
                        "focusinBubbles": true,
                        "noCloneChecked": false,
                        "optDisabled": true,
@@ -93,6 +95,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "checkOn": true,
                        "clearCloneStyle": false,
                        "cors": false,
+                       "createHTMLDocument": true,
                        "focusinBubbles": true,
                        "noCloneChecked": false,
                        "optDisabled": true,
@@ -101,7 +104,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "radioValue": false,
                        "reliableMarginRight": true
                };
-       } else if ( /(6|7|8)\.0(\.\d+|) safari/i.test( userAgent ) ) {
+       } else if ( /(6|7)\.0(\.\d+|) safari/i.test( userAgent ) ) {
                expected = {
                        "ajax": true,
                        "boxSizingReliable": true,
@@ -109,6 +112,24 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "checkOn": true,
                        "clearCloneStyle": true,
                        "cors": true,
+                       "createHTMLDocument": true,
+                       "focusinBubbles": false,
+                       "noCloneChecked": true,
+                       "optDisabled": true,
+                       "optSelected": true,
+                       "pixelPosition": false,
+                       "radioValue": true,
+                       "reliableMarginRight": true
+               };
+       } else if ( /8.0(\.\d+|) safari/i.test( userAgent ) ) {
+               expected = {
+                       "ajax": true,
+                       "boxSizingReliable": true,
+                       "checkClone": true,
+                       "checkOn": true,
+                       "clearCloneStyle": true,
+                       "cors": true,
+                       "createHTMLDocument": false,
                        "focusinBubbles": false,
                        "noCloneChecked": true,
                        "optDisabled": true,
@@ -125,6 +146,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "checkOn": true,
                        "clearCloneStyle": true,
                        "cors": true,
+                       "createHTMLDocument": true,
                        "focusinBubbles": false,
                        "noCloneChecked": true,
                        "optDisabled": true,
@@ -141,6 +163,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "checkOn": true,
                        "clearCloneStyle": true,
                        "cors": true,
+                       "createHTMLDocument": true,
                        "focusinBubbles": false,
                        "noCloneChecked": true,
                        "optDisabled": true,
@@ -157,6 +180,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "checkOn": false,
                        "clearCloneStyle": true,
                        "cors": true,
+                       "createHTMLDocument": true,
                        "focusinBubbles": false,
                        "noCloneChecked": true,
                        "optDisabled": true,
@@ -173,6 +197,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
                        "checkOn": false,
                        "clearCloneStyle": false,
                        "cors": true,
+                       "createHTMLDocument": true,
                        "focusinBubbles": false,
                        "noCloneChecked": true,
                        "optDisabled": false,