From 760e9bb02d2a617cebab39546e80cfffb093672a Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 29 Dec 2025 16:32:10 -0500 Subject: [PATCH 1/2] Add tests for import bytes --- .../bytes-module/bom-utf-16be.json | Bin 0 -> 40 bytes .../bytes-module/bom-utf-16le.json | Bin 0 -> 40 bytes .../bytes-module/bom-utf-8.json | 1 + .../bytes-module/charset-1250.html | 26 ++++ .../bytes-module/charset-bom.any.js | 32 +++++ .../bytes-module/charset.html | 56 +++++++++ .../the-script-element/bytes-module/file.bin | 1 + .../the-script-element/bytes-module/file.js | 1 + .../the-script-element/bytes-module/file.txt | 1 + .../bytes-module/ignore-content-type.html | 114 ++++++++++++++++++ .../bytes-module/ignore-extension.any.js | 8 ++ .../the-script-element/bytes-module/image.png | Bin 0 -> 67 bytes .../bytes-module/serve-with-content-type.py | 17 +++ .../bytes-module/sync-module.html | 86 +++++++++++++ .../bytes-module/windows-1250.json | 1 + 15 files changed, 344 insertions(+) create mode 100644 html/semantics/scripting-1/the-script-element/bytes-module/bom-utf-16be.json create mode 100644 html/semantics/scripting-1/the-script-element/bytes-module/bom-utf-16le.json create mode 100644 html/semantics/scripting-1/the-script-element/bytes-module/bom-utf-8.json create mode 100644 html/semantics/scripting-1/the-script-element/bytes-module/charset-1250.html create mode 100644 html/semantics/scripting-1/the-script-element/bytes-module/charset-bom.any.js create mode 100644 html/semantics/scripting-1/the-script-element/bytes-module/charset.html create mode 100644 html/semantics/scripting-1/the-script-element/bytes-module/file.bin create mode 100644 html/semantics/scripting-1/the-script-element/bytes-module/file.js create mode 100644 html/semantics/scripting-1/the-script-element/bytes-module/file.txt create mode 100644 html/semantics/scripting-1/the-script-element/bytes-module/ignore-content-type.html create mode 100644 html/semantics/scripting-1/the-script-element/bytes-module/ignore-extension.any.js create mode 100644 html/semantics/scripting-1/the-script-element/bytes-module/image.png create mode 100644 html/semantics/scripting-1/the-script-element/bytes-module/serve-with-content-type.py create mode 100644 html/semantics/scripting-1/the-script-element/bytes-module/sync-module.html create mode 100644 html/semantics/scripting-1/the-script-element/bytes-module/windows-1250.json diff --git a/html/semantics/scripting-1/the-script-element/bytes-module/bom-utf-16be.json b/html/semantics/scripting-1/the-script-element/bytes-module/bom-utf-16be.json new file mode 100644 index 0000000000000000000000000000000000000000..d22a45a591079d6caea71404eb0190e7094f321c GIT binary patch literal 40 ocmezOpP`yTfkBBOg&~ol1c;Rwtib#XhE#?eAj}7fC@|Cl0J^gW#sB~S literal 0 HcmV?d00001 diff --git a/html/semantics/scripting-1/the-script-element/bytes-module/bom-utf-16le.json b/html/semantics/scripting-1/the-script-element/bytes-module/bom-utf-16le.json new file mode 100644 index 0000000000000000000000000000000000000000..4d1aa264a697b224eadbfe993cafeaac810acdd2 GIT binary patch literal 40 ocmezWubM%DL5U%SA(5d3h?N+u!2Aq`RE8WN%m<1nFw`;t0Kj|)#sB~S literal 0 HcmV?d00001 diff --git a/html/semantics/scripting-1/the-script-element/bytes-module/bom-utf-8.json b/html/semantics/scripting-1/the-script-element/bytes-module/bom-utf-8.json new file mode 100644 index 00000000000000..07ba933e8608da --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/bytes-module/bom-utf-8.json @@ -0,0 +1 @@ +{ "data": "hello" } \ No newline at end of file diff --git a/html/semantics/scripting-1/the-script-element/bytes-module/charset-1250.html b/html/semantics/scripting-1/the-script-element/bytes-module/charset-1250.html new file mode 100644 index 00000000000000..def356ba126ff1 --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/bytes-module/charset-1250.html @@ -0,0 +1,26 @@ + + +Bytes modules: Windows-1250 decoding + + +
+ + \ No newline at end of file diff --git a/html/semantics/scripting-1/the-script-element/bytes-module/charset-bom.any.js b/html/semantics/scripting-1/the-script-element/bytes-module/charset-bom.any.js new file mode 100644 index 00000000000000..f2012fdc9dce0a --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/bytes-module/charset-bom.any.js @@ -0,0 +1,32 @@ +// META: global=window,dedicatedworker,sharedworker +// META: script=/common/utils.js + +promise_test(async () => { + const mod = await import('./bom-utf-8.json', { with: { type: 'bytes' } }); + assert_true(mod instanceof Uint8Array); + assert_array_equals(Array.from(mod), [ + 239, 187, 191, 123, 32, 34, 100, 97, 116, 97, 34, + 58, 32, 34, 104, 101, 108, 108, 111, 34, 32, 125, + ]); +}, 'UTF-8 BOM should be ignored when importing bytes'); + +promise_test(async () => { + const mod = await import('./bom-utf-16be.json', { with: { type: 'bytes' } }); + assert_true(mod instanceof Uint8Array); + assert_array_equals(Array.from(mod), [ + 254, 255, 0, 123, 0, 32, 0, 34, 0, 100, 0, 97, 0, 116, + 0, 97, 0, 34, 0, 58, 0, 32, 0, 34, 0, 104, 0, 101, + 0, 108, 0, 108, 0, 111, 0, 34, 0, 32, 0, 125, + ]); +}, 'UTF-16BE BOM should be ignored when importing bytes'); + +promise_test(async () => { + const mod = await import('./bom-utf-16le.json', { with: { type: 'bytes' } }); + assert_true(mod instanceof Uint8Array); + assert_array_equals(Array.from(mod), [ + 255, 254, 123, 0, 32, 0, 34, 0, 100, 0, 97, 0, 116, 0, + 97, 0, 34, 0, 58, 0, 32, 0, 34, 0, 104, 0, 101, 0, + 108, 0, 108, 0, 111, 0, 34, 0, 32, 0, 125, 0, + ]); +}, 'UTF-16LE BOM should be ignored when importing bytes'); + diff --git a/html/semantics/scripting-1/the-script-element/bytes-module/charset.html b/html/semantics/scripting-1/the-script-element/bytes-module/charset.html new file mode 100644 index 00000000000000..fbdf15a3a04533 --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/bytes-module/charset.html @@ -0,0 +1,56 @@ + + +Bytes modules: UTF-8 decoding + + +
+ + + + + \ No newline at end of file diff --git a/html/semantics/scripting-1/the-script-element/bytes-module/file.bin b/html/semantics/scripting-1/the-script-element/bytes-module/file.bin new file mode 100644 index 00000000000000..271b60b1fdaa88 --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/bytes-module/file.bin @@ -0,0 +1 @@ +mycontent diff --git a/html/semantics/scripting-1/the-script-element/bytes-module/file.js b/html/semantics/scripting-1/the-script-element/bytes-module/file.js new file mode 100644 index 00000000000000..271b60b1fdaa88 --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/bytes-module/file.js @@ -0,0 +1 @@ +mycontent diff --git a/html/semantics/scripting-1/the-script-element/bytes-module/file.txt b/html/semantics/scripting-1/the-script-element/bytes-module/file.txt new file mode 100644 index 00000000000000..271b60b1fdaa88 --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/bytes-module/file.txt @@ -0,0 +1 @@ +mycontent diff --git a/html/semantics/scripting-1/the-script-element/bytes-module/ignore-content-type.html b/html/semantics/scripting-1/the-script-element/bytes-module/ignore-content-type.html new file mode 100644 index 00000000000000..0462d9114617ab --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/bytes-module/ignore-content-type.html @@ -0,0 +1,114 @@ + + +Bytes modules: Content-Type + + +
+ + + + + + + diff --git a/html/semantics/scripting-1/the-script-element/bytes-module/ignore-extension.any.js b/html/semantics/scripting-1/the-script-element/bytes-module/ignore-extension.any.js new file mode 100644 index 00000000000000..125f329f284a8a --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/bytes-module/ignore-extension.any.js @@ -0,0 +1,8 @@ +// META: global=window,dedicatedworker,sharedworker + +for (const name of ["file", "file.bin", "file.js", "file.txt"]) { + promise_test(async t => { + const result = await import(`./${name}`, { with: { type: "bytes" } }); + assert_equals(result, "mycontent\n"); + }, `Extension: ${name}`); +} \ No newline at end of file diff --git a/html/semantics/scripting-1/the-script-element/bytes-module/image.png b/html/semantics/scripting-1/the-script-element/bytes-module/image.png new file mode 100644 index 0000000000000000000000000000000000000000..252d9502d8573d033e633f5e377d81bebf8afd36 GIT binary patch literal 67 zcmeAS@N?(olHy`uVBq!ia0vp^j35jm7|ip2ssJf2PZ!6K3dZCFAe)JSvAC2`0?1 + +Bytes modules + + +
+ + diff --git a/html/semantics/scripting-1/the-script-element/bytes-module/windows-1250.json b/html/semantics/scripting-1/the-script-element/bytes-module/windows-1250.json new file mode 100644 index 00000000000000..9d6aaccbf4b58d --- /dev/null +++ b/html/semantics/scripting-1/the-script-element/bytes-module/windows-1250.json @@ -0,0 +1 @@ +{ "data": "�湿�" } From 64410ac86459c533493587acec26e23ae4458f04 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 7 May 2026 22:27:36 -0400 Subject: [PATCH 2/2] add test for `connect-src` --- .../connect-src-bytes-import-blocked.sub.html | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 content-security-policy/connect-src/connect-src-bytes-import-blocked.sub.html diff --git a/content-security-policy/connect-src/connect-src-bytes-import-blocked.sub.html b/content-security-policy/connect-src/connect-src-bytes-import-blocked.sub.html new file mode 100644 index 00000000000000..8aed9d58cd6dd5 --- /dev/null +++ b/content-security-policy/connect-src/connect-src-bytes-import-blocked.sub.html @@ -0,0 +1,33 @@ + + + + connect-src-bytes-import-blocked + + + + + + + + +