mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 03:25:13 +00:00
LibWeb: Don't prepare script when src attribute is removed
This commit is contained in:
parent
63b451cb46
commit
08b5cae199
Notes:
github-actions[bot]
2025-02-22 10:40:37 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/08b5cae199d Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3658 Reviewed-by: https://github.com/gmta ✅
3 changed files with 46 additions and 0 deletions
|
@ -64,6 +64,11 @@ void HTMLScriptElement::attribute_changed(FlyString const& name, Optional<String
|
|||
if (namespace_.has_value())
|
||||
return;
|
||||
|
||||
// AD-HOC: This ensures that prepare_script() is not called when the src attribute is removed.
|
||||
// See: https://github.com/whatwg/html/pull/10188/files#r1685905457 for more information.
|
||||
if (!value.has_value())
|
||||
return;
|
||||
|
||||
// 2. If localName is src, then run the script HTML element post-connection steps, given element.
|
||||
post_connection();
|
||||
} else if (name == HTML::AttributeNames::async) {
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
Harness status: OK
|
||||
|
||||
Found 1 tests
|
||||
|
||||
1 Pass
|
||||
Pass Removing the `src` content attribute does not 'prepare' the script
|
|
@ -0,0 +1,35 @@
|
|||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<link rel=help href=https://github.com/whatwg/html/pull/10188/files#r1685905457>
|
||||
<title>Remove src attribute does not "prepare the script"</title>
|
||||
<script src="../../../../resources/testharness.js"></script>
|
||||
<script src="../../../../resources/testharnessreport.js"></script>
|
||||
|
||||
<body>
|
||||
<script>
|
||||
test(() => {
|
||||
// Flags that the script element in this test will change, if it incorrectly
|
||||
// executes.
|
||||
window.didExecute = false;
|
||||
window.innerTextExecuted = false;
|
||||
|
||||
const script = document.createElement('script');
|
||||
// Invalid type, so the script won't execute upon insertion.
|
||||
script.type = 'invalid';
|
||||
script.src = 'resources/flag-setter.js';
|
||||
script.innerText = 'window.innerTextExecuted = true';
|
||||
document.body.append(script);
|
||||
assert_false(window.didExecute);
|
||||
assert_false(window.innerTextExecuted);
|
||||
|
||||
// Make script valid, but don't immediately execute it.
|
||||
script.type = '';
|
||||
|
||||
// Removing the `src` content attribute does not trigger the "prepare a
|
||||
// script" algorithm on the script.
|
||||
script.removeAttribute('src');
|
||||
assert_false(window.didExecute);
|
||||
assert_false(window.innerTextExecuted);
|
||||
}, "Removing the `src` content attribute does not 'prepare' the script");
|
||||
</script>
|
||||
</body>
|
Loading…
Add table
Reference in a new issue