diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2019-07-29 22:06:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-29 22:06:18 +0200 |
commit | 2d9d6d5b476b9cd1c546592817ef8e96b32e5792 (patch) | |
tree | 8cddea99155dd643408a86172bbf25797eca4e7e /test/unit/core.js | |
parent | 90f78b9aab9c99ff3ffcccb1db602670e9707fa0 (diff) | |
download | jquery-2d9d6d5b476b9cd1c546592817ef8e96b32e5792.tar.gz jquery-2d9d6d5b476b9cd1c546592817ef8e96b32e5792.zip |
Selector: Make selector-native's isXMLDoc recognize HTML-embedded SVG
This commit also backports some jQuery.isXMLDoc tests from master so that this
behavior doesn't regress.
(partially cherry-picked from 79b74e043a4ee737d44a95094ff1184e40bd5b16)
Closes gh-4438
Ref jquery/sizzle#378
Ref jquery/sizzle#436
Diffstat (limited to 'test/unit/core.js')
-rw-r--r-- | test/unit/core.js | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/test/unit/core.js b/test/unit/core.js index 28f40ab56..2f40462f3 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -380,6 +380,52 @@ QUnit.test( "isXMLDoc - HTML", function( assert ) { document.body.removeChild( iframe ); } ); +QUnit.test( "isXMLDoc - embedded SVG", function( assert ) { + assert.expect( 6 ); + + var htmlTree = jQuery( "<div>" + + "<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='1' width='1'>" + + "<desc></desc>" + + "</svg>" + + "</div>" + )[ 0 ]; + + assert.strictEqual( jQuery.isXMLDoc( htmlTree ), false, "disconnected div element" ); + assert.strictEqual( jQuery.isXMLDoc( htmlTree.firstChild ), true, + "disconnected HTML-embedded SVG root element" ); + + assert.strictEqual( jQuery.isXMLDoc( htmlTree.firstChild.firstChild ), true, + "disconnected HTML-embedded SVG child element" ); + + document.getElementById( "qunit-fixture" ).appendChild( htmlTree ); + assert.strictEqual( jQuery.isXMLDoc( htmlTree ), false, "connected div element" ); + assert.strictEqual( jQuery.isXMLDoc( htmlTree.firstChild ), true, + "connected HTML-embedded SVG root element" ); + + assert.strictEqual( jQuery.isXMLDoc( htmlTree.firstChild.firstChild ), true, + "disconnected HTML-embedded SVG child element" ); +} ); + +QUnit.test( "isXMLDoc - XML", function( assert ) { + assert.expect( 8 ); + + var xml = createDashboardXML(); + var svg = jQuery.parseXML( + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" " + + "\"http://www.w3.org/Gaphics/SVG/1.1/DTD/svg11.dtd\">" + + "<svg version='1.1' xmlns='http://www.w3.org/2000/svg'><desc/></svg>" + ); + assert.ok( jQuery.isXMLDoc( xml ), "XML document" ); + assert.ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" ); + assert.ok( jQuery.isXMLDoc( xml.documentElement.firstChild ), "XML child element" ); + assert.ok( jQuery.isXMLDoc( jQuery( "tab", xml )[ 0 ] ), "XML tab Element" ); + + assert.ok( jQuery.isXMLDoc( svg ), "SVG document" ); + assert.ok( jQuery.isXMLDoc( svg.documentElement ), "SVG documentElement" ); + assert.ok( jQuery.isXMLDoc( svg.documentElement.firstChild ), "SVG child element" ); + assert.ok( jQuery.isXMLDoc( jQuery( "desc", svg )[ 0 ] ), "XML desc Element" ); +} ); + QUnit.test( "XSS via location.hash", function( assert ) { var done = assert.async(); assert.expect( 1 ); @@ -399,14 +445,6 @@ QUnit.test( "XSS via location.hash", function( assert ) { } } ); -QUnit.test( "isXMLDoc - XML", function( assert ) { - assert.expect( 3 ); - var xml = createDashboardXML(); - assert.ok( jQuery.isXMLDoc( xml ), "XML document" ); - assert.ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" ); - assert.ok( jQuery.isXMLDoc( jQuery( "tab", xml )[ 0 ] ), "XML Tab Element" ); -} ); - QUnit.test( "jQuery('html')", function( assert ) { assert.expect( 18 ); |