From c5c30735311c74c60689fcabdcf2cb192524000e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Go=C5=82=C4=99biowski?= Date: Wed, 2 Mar 2016 12:28:00 +0100 Subject: [PATCH] Core: drop the document.implementation.createHTMLDocument usage The document.implementation.createHTMLDocument("") method creates inert documents which is good but using it has introduced issues around anchor elements href property not resolving according to the current document. Because of that, this patch is getting backed out on 1.x/2.x branches. Refs cfe468f29c4cbe1a457d0feb17dec90dcfd7c280 Refs gh-1505 Fixes gh-2941 --- src/core/parseHTML.js | 14 +++----------- src/core/support.js | 18 ------------------ test/unit/core.js | 16 ---------------- test/unit/support.js | 15 --------------- 4 files changed, 3 insertions(+), 60 deletions(-) delete mode 100644 src/core/support.js diff --git a/src/core/parseHTML.js b/src/core/parseHTML.js index 87c2147d1..3524abd63 100644 --- a/src/core/parseHTML.js +++ b/src/core/parseHTML.js @@ -2,11 +2,8 @@ define( [ "../core", "../var/document", "./var/rsingleTag", - "../manipulation/buildFragment", - - // This is the only module that needs core/support - "./support" -], function( jQuery, document, rsingleTag, buildFragment, support ) { + "../manipulation/buildFragment" +], function( jQuery, document, rsingleTag, buildFragment ) { // Argument "data" should be string of html // context (optional): If specified, the fragment will be created in this context, @@ -20,12 +17,7 @@ jQuery.parseHTML = function( data, context, keepScripts ) { keepScripts = context; context = false; } - - // Stop scripts or inline event handlers from being executed immediately - // by using document.implementation - context = context || ( support.createHTMLDocument ? - document.implementation.createHTMLDocument( "" ) : - document ); + context = context || document; var parsed = rsingleTag.exec( data ), scripts = !keepScripts && []; diff --git a/src/core/support.js b/src/core/support.js deleted file mode 100644 index 0609a700b..000000000 --- a/src/core/support.js +++ /dev/null @@ -1,18 +0,0 @@ -define( [ - "../var/document", - "../var/support" -], function( document, support ) { - -// Support: Safari 8+ -// In Safari 8 documents created via document.implementation.createHTMLDocument -// collapse sibling forms: the second one becomes a child of the first one. -// Because of that, this security measure has to be disabled in Safari 8. -// https://bugs.webkit.org/show_bug.cgi?id=137337 -support.createHTMLDocument = ( function() { - var body = document.implementation.createHTMLDocument( "" ).body; - body.innerHTML = "
"; - return body.childNodes.length === 2; -} )(); - -return support; -} ); diff --git a/test/unit/core.js b/test/unit/core.js index a9e93989c..accdae8e1 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -1491,22 +1491,6 @@ QUnit.test("jQuery.parseHTML", function( assert ) { assert.ok( jQuery.parseHTML("<#if>

This is a test.

<#/if>") || true, "Garbage input should not cause error" ); }); -if ( jQuery.support.createHTMLDocument && !/opera.*version\/12\.1/i.test( navigator.userAgent ) ) { - QUnit.asyncTest( "jQuery.parseHTML", function( assert ) { - assert.expect( 1 ); - - Globals.register( "parseHTMLError" ); - - jQuery.globalEval( "parseHTMLError = false;" ); - jQuery.parseHTML( "" ); - - window.setTimeout( function() { - QUnit.start(); - assert.equal( window.parseHTMLError, false, "onerror eventhandler has not been called." ); - }, 2000 ); - } ); -} - QUnit.test( "jQuery.parseJSON", function( assert ) { assert.expect( 20 ); diff --git a/test/unit/support.js b/test/unit/support.js index 5d3e38a4b..af2bd9238 100644 --- a/test/unit/support.js +++ b/test/unit/support.js @@ -65,7 +65,6 @@ testIframeWithCallback( "checkOn": true, "clearCloneStyle": version >= 13, "cors": true, - "createHTMLDocument": true, "focusin": false, "noCloneChecked": true, "optDisabled": true, @@ -84,7 +83,6 @@ testIframeWithCallback( "checkOn": true, "clearCloneStyle": true, "cors": true, - "createHTMLDocument": true, "focusin": false, "noCloneChecked": true, "optDisabled": true, @@ -103,7 +101,6 @@ testIframeWithCallback( "checkOn": true, "clearCloneStyle": false, "cors": true, - "createHTMLDocument": true, "focusin": true, "noCloneChecked": false, "optDisabled": true, @@ -122,7 +119,6 @@ testIframeWithCallback( "checkOn": true, "clearCloneStyle": false, "cors": false, - "createHTMLDocument": true, "focusin": true, "noCloneChecked": false, "optDisabled": true, @@ -144,7 +140,6 @@ testIframeWithCallback( "checkOn": true, "clearCloneStyle": true, "cors": true, - "createHTMLDocument": true, "focusin": false, "noCloneChecked": true, "optDisabled": true, @@ -163,7 +158,6 @@ testIframeWithCallback( "checkOn": true, "clearCloneStyle": true, "cors": true, - "createHTMLDocument": true, "focusin": false, "noCloneChecked": true, "optDisabled": true, @@ -182,7 +176,6 @@ testIframeWithCallback( "checkOn": true, "clearCloneStyle": true, "cors": true, - "createHTMLDocument": false, "focusin": false, "noCloneChecked": true, "optDisabled": true, @@ -201,7 +194,6 @@ testIframeWithCallback( "checkOn": true, "clearCloneStyle": true, "cors": true, - "createHTMLDocument": true, "focusin": false, "noCloneChecked": true, "optDisabled": true, @@ -220,7 +212,6 @@ testIframeWithCallback( "checkOn": false, "clearCloneStyle": true, "cors": true, - "createHTMLDocument": true, "focusin": false, "noCloneChecked": true, "optDisabled": true, @@ -239,7 +230,6 @@ testIframeWithCallback( "checkOn": true, "clearCloneStyle": true, "cors": true, - "createHTMLDocument": true, "focusin": false, "noCloneChecked": true, "optDisabled": true, @@ -258,7 +248,6 @@ testIframeWithCallback( "checkOn": true, "clearCloneStyle": true, "cors": true, - "createHTMLDocument": true, "focusin": false, "noCloneChecked": true, "optDisabled": true, @@ -277,7 +266,6 @@ testIframeWithCallback( "checkOn": true, "clearCloneStyle": true, "cors": true, - "createHTMLDocument": false, "focusin": false, "noCloneChecked": true, "optDisabled": true, @@ -296,7 +284,6 @@ testIframeWithCallback( "checkOn": true, "clearCloneStyle": true, "cors": true, - "createHTMLDocument": true, "focusin": false, "noCloneChecked": true, "optDisabled": true, @@ -315,7 +302,6 @@ testIframeWithCallback( "checkOn": false, "clearCloneStyle": true, "cors": true, - "createHTMLDocument": true, "focusin": false, "noCloneChecked": true, "optDisabled": true, @@ -334,7 +320,6 @@ testIframeWithCallback( "checkOn": false, "clearCloneStyle": false, "cors": true, - "createHTMLDocument": true, "focusin": false, "noCloneChecked": true, "optDisabled": false,