🌐 AI搜索 & 代理 主页
Skip to content

Commit 5e40c14

Browse files
committed
Selector:Manipulation: Fix DOM manip within template contents
The `<template/>` element `contents` property is a document fragment that may have a `null` `documentElement`. In Safari 16 this happens in more cases due to recent spec changes - in particular, even if that document fragment is explicitly adopted into an outer document. We're testing both of those cases now. The crash used to happen in `jQuery.contains` which is an alias for `Sizzle.contains` in jQuery 3.x. The Sizzle fix is at jquery/sizzle#490, released in Sizzle `2.3.8`. This version of Sizzle is included in the parent commit. Fixes gh-5147 Closes gh-5159 Ref jquery/sizzle#490 Ref gh-5158
1 parent bc78d56 commit 5e40c14

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/unit/manipulation.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2837,6 +2837,49 @@ QUnit.test( "Make sure tr is not appended to the wrong tbody (gh-3439)", functio
28372837
assert.strictEqual( htmlOut, htmlExpected );
28382838
} );
28392839

2840+
[ true, false ].forEach( function( adoptedCase ) {
2841+
QUnit[
2842+
typeof HTMLTemplateElement === "function" ?
2843+
"test" :
2844+
"skip"
2845+
]( "Manip within <template /> content moved back & forth doesn't throw - " + (
2846+
adoptedCase ? "explicitly adopted" : "not explicitly adopted"
2847+
) + " (gh-5147)",
2848+
function( assert ) {
2849+
assert.expect( 1 );
2850+
2851+
var fragment, diva, divb,
2852+
div = jQuery( "" +
2853+
"<div>\n" +
2854+
" <div><div class='a'></div></div>\n" +
2855+
" <div><div class='b'></div></div>\n" +
2856+
"</div>" +
2857+
"" ),
2858+
template = jQuery( "<template></template>" );
2859+
2860+
jQuery( "#qunit-fixture" )
2861+
.append( div )
2862+
.append( template );
2863+
2864+
fragment = template[ 0 ].content;
2865+
diva = div.find( ".a" );
2866+
divb = div.find( ".b" );
2867+
2868+
if ( adoptedCase ) {
2869+
document.adoptNode( fragment );
2870+
}
2871+
2872+
fragment.appendChild( div.children()[ 0 ] );
2873+
fragment.appendChild( div.children()[ 0 ] );
2874+
2875+
diva.insertBefore( divb );
2876+
2877+
assert.strictEqual( diva.siblings( ".b" ).length, 1,
2878+
"Insertion worked" );
2879+
}
2880+
);
2881+
} );
2882+
28402883
QUnit.test( "Make sure tags with single-character names are found (gh-4124)", function( assert ) {
28412884
assert.expect( 1 );
28422885

0 commit comments

Comments
 (0)