Skip to content

Commit

Permalink
Manipulation: Support $el.html(selfRemovingScript)
Browse files Browse the repository at this point in the history
Don't try to remove a script element that has already removed itself.

Fixes jquerygh-5377
Closes jquerygh-5378

(cherry-picked from commit 937923d)
  • Loading branch information
gibson042 authored and mgol committed Jan 8, 2024
1 parent b922eed commit cbc15c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/core/DOMEval.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ define( [
}
}
}
doc.head.appendChild( script ).parentNode.removeChild( script );
if ( doc.head.appendChild( script ).parentNode ) {
script.parentNode.removeChild( script );
}
}

return DOMEval;
Expand Down
15 changes: 15 additions & 0 deletions test/unit/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit cbc15c9

Please sign in to comment.