Manipulation: Support $el.html(selfRemovingScript)

Don't try to remove a script element that has already removed itself.

Fixes gh-5377
Closes gh-5378

(cherry-picked from commit 937923d9ee)
This commit is contained in:
Richard Gibson 2024-01-08 12:30:39 -05:00 committed by Michał Gołębiowski-Owczarek
parent b922eed934
commit cbc15c9c31
No known key found for this signature in database
2 changed files with 18 additions and 1 deletions

View File

@ -36,7 +36,9 @@ define( [
}
}
}
doc.head.appendChild( script ).parentNode.removeChild( script );
if ( doc.head.appendChild( script ).parentNode ) {
script.parentNode.removeChild( script );
}
}
return DOMEval;

View File

@ -1871,6 +1871,21 @@ QUnit[
}, 1000 );
} );
QUnit.test( "html(self-removing script) (gh-5377)", function( assert ) {
assert.expect( 2 );
var $fixture = jQuery( "#qunit-fixture" );
$fixture.html(
[
"<script>document.currentScript.parentNode.removeChild( document.currentScript ); QUnit.assert.ok( true, 'removed document.currentScript' );</script>",
"<div>",
"<script>document.currentScript.parentNode.removeChild( document.currentScript ); QUnit.assert.ok( true, 'removed inner document.currentScript' );</script>",
"</div>"
].join( "" )
);
} );
QUnit.test( "html(Function) with incoming value -- direct selection", function( assert ) {
assert.expect( 4 );