mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 18:17:22 +02:00
LibWeb: Make HTMLScriptElement.src getter resolve to absolute URL
The src IDL attribute was previously implemented as an inline getter that returned the raw attribute value. This broke spec semantics and sites like Telegram Web that rely on document.currentScript.src to compute Webpack’s publicPath. According to the HTML Standard: https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes For URL-reflecting attributes: 1. If contentAttributeValue is null, then return the empty string. 2. Let urlString be the result of encoding-parsing-and-serializing a URL given contentAttributeValue, relative to element’s node document. 3. If urlString is not failure, then return urlString. This patch moves the getter to HTMLScriptElement.cpp and implements these steps.
This commit is contained in:
committed by
Jelle Raaijmakers
parent
f44e42d27c
commit
4ff7c9043b
Notes:
github-actions[bot]
2025-10-07 19:56:07 +00:00
Author: https://github.com/shlyakpavel Commit: https://github.com/LadybirdBrowser/ladybird/commit/4ff7c9043b2 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6255 Reviewed-by: https://github.com/gmta ✅ Reviewed-by: https://github.com/shannonbooth Reviewed-by: https://github.com/tete17
22
Tests/LibWeb/Text/input/htmlscript-src-reflection.html
Normal file
22
Tests/LibWeb/Text/input/htmlscript-src-reflection.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<script src="include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
const script = document.createElement("script");
|
||||
script.src = "./dummy.js"; // not appended/loaded; we only check the getter resolution
|
||||
const value = script.src;
|
||||
|
||||
// Print booleans so expected output is stable.
|
||||
const is_string = typeof value === "string";
|
||||
println(`is_string = ${is_string}`);
|
||||
|
||||
// Must be absolute per spec: has a scheme like "file:" or "http:"
|
||||
let has_protocol = false;
|
||||
try { has_protocol = !!new URL(value).protocol; } catch {}
|
||||
println(`has_protocol = ${has_protocol}`);
|
||||
|
||||
// Should end with the filename we set.
|
||||
const ends_with = value.endsWith("/dummy.js");
|
||||
println(`ends_with_dummy = ${ends_with}`);
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user