From cbc15c9c31fa855304b4b63c13a0c8fb0ef61275 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Mon, 8 Jan 2024 12:30:39 -0500 Subject: [PATCH] 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 937923d9ee8dfd19008447b5059cbd13ee5a23ac) --- src/core/DOMEval.js | 4 +++- test/unit/manipulation.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core/DOMEval.js b/src/core/DOMEval.js index 59f6e0247..e3ecd60ac 100644 --- a/src/core/DOMEval.js +++ b/src/core/DOMEval.js @@ -36,7 +36,9 @@ define( [ } } } - doc.head.appendChild( script ).parentNode.removeChild( script ); + if ( doc.head.appendChild( script ).parentNode ) { + script.parentNode.removeChild( script ); + } } return DOMEval; diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 975813e34..f894cc626 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -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( + [ + "", + "
", + "", + "
" + ].join( "" ) + ); +} ); + QUnit.test( "html(Function) with incoming value -- direct selection", function( assert ) { assert.expect( 4 ); -- 2.39.5