Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "data": "hello" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<meta charset="windows-1250">
<title>Bytes modules: Windows-1250 decoding</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script type="module">
import mod from "../serve-with-content-type.py?fn=bytes-module/utf-8.json" with { type: "bytes" };
test(() => {
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,
]);
}, "Bytes should be loaded as is, even when encoded in utf-8 and served though document's encoding is windows-1250");
</script>
<script type="module">
import mod from "../serve-with-content-type.py?fn=bytes-module/windows-1250.json&ct=text/json%3Bcharset=windows-1250" with { type: "bytes"};
test(() => {
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,
]);
}, "Bytes should be loaded as is, even when encoded in windows-1250 and served with a windows-1250 charset response header, and this document's encoding is windows-1250");
</script>
Original file line number Diff line number Diff line change
@@ -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');

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Bytes modules: UTF-8 decoding</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script type="module" onerror="unreachable()">
import mod from "../serve-with-content-type.py?fn=bytes-module/utf-8.json&ct=text/json%3Bcharset=utf-8" with { type: "bytes" };
test(() => {
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,
]);
}, "Bytes should be loaded as is, even when charset=utf8 is specified");
</script>
<script type="module" onerror="unreachable()">
import mod from "../serve-with-content-type.py?fn=bytes-module/utf-8.json&ct=text/json%3Bcharset=shift-jis" with { type: "bytes" };
test(() => {
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,
]);
}, "Bytes should be loaded as is, even when charset=shift-jis is specified");
</script>
<script type="module" onerror="unreachable()">
import mod from "../serve-with-content-type.py?fn=bytes-module/utf-8.json&ct=text/json%3Bcharset=windows-1252" with { type: "bytes" };
test(() => {
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,
]);
}, "Bytes should be loaded as is, even when charset=windows-1252 is specified");
</script>
<script type="module" onerror="unreachable()">
import mod from "../serve-with-content-type.py?fn=bytes-module/utf-8.json&ct=text/json%3Bcharset=utf-7" with { type: "bytes" };;
test(() => {
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,
]);
}, "Bytes should be loaded as is, even when charset=utf-7 is specified");
</script>
<script type="module" onerror="unreachable()">
import mod from "../serve-with-content-type.py?fn=bytes-module/windows-1250.json&ct=text/json%3Bcharset=windows-1250" with { type: "bytes" };
test(() => {
assert_true(mod instanceof Uint8Array);
assert_array_equals(Array.from(mod), [
123, 32, 34, 100, 97, 116, 97, 34, 58, 32, 34, 239, 191,
189, 230, 185, 191, 239, 191, 189, 34, 32, 125, 10,
]);
}, "Bytes should be loaded as is, even when encoded in windows-1250 and served with a windows-1250 charset response header");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mycontent
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mycontent
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mycontent
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Bytes modules: Content-Type</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script>
function check(t, v) {
t.step(() => {
assert_true(v instanceof Uint8Array);
const expected = [
0x89,
0x50,
0x4e,
0x47,
0xd,
0xa,
0x1a,
0xa,
0x0,
0x0,
0x0,
0xd,
0x49,
0x48,
0x44,
0x52,
0x0,
0x0,
0x0,
0x1,
0x0,
0x0,
0x0,
0x1,
0x1,
0x0,
0x0,
0x0,
0x0,
0x37,
0x6e,
0xf9,
0x24,
0x0,
0x0,
0x0,
0xa,
0x49,
0x44,
0x41,
0x54,
0x78,
0x1,
0x63,
0x60,
0x0,
0x0,
0x0,
0x2,
0x0,
0x1,
0x73,
0x75,
0x1,
0x18,
0x0,
0x0,
0x0,
0x0,
0x49,
0x45,
0x4e,
0x44,
0xae,
0x42,
0x60,
0x82,
];
assert_array_equals(Array.from(v), expected);
t.done();
});
}
const t1 = async_test("image/png");
const t2 = async_test("application/octet-stream");
const t3 = async_test("application/binary");
const t4 = async_test("image/svg+xml");
const t5 = async_test("image/png;boundary=something");
const t6 = async_test("text/html");
</script>
<script type="module" onerror="t1.step(() => assert_unreached(event))">
import v from "../serve-with-content-type.py?fn=bytes-module/image.png&ct=image/png" with { type: "bytes" };
check(t1, v);
</script>
<script type="module" onerror="t2.step(() => assert_unreached(event))">
import v from "../serve-with-content-type.py?fn=bytes-module/image.png&ct=application/octet-stream" with { type: "bytes" };
check(t2, v);
</script>
<script type="module" onerror="t3.step(() => assert_unreached(event))">
import v from "../serve-with-content-type.py?fn=bytes-module/image.png&ct=application/binary" with { type: "bytes" };
check(t3, v);
</script>
<script type="module" onerror="t4.step(() => assert_unreached(event))">
import v from "../serve-with-content-type.py?fn=bytes-module/image.png&ct=image/svg%2Bxml" with { type: "bytes" };
check(t4, v);
</script>
<script type="module" onerror="t5.step(() => assert_unreached(event))">
import v from "../serve-with-content-type.py?fn=bytes-module/image.png&ct=image/png;boundary=something" with { type: "bytes" };
check(t5, v);
</script>
<script type="module" onerror="t6.step(() => assert_unreached(event))">
import v from "../serve-with-content-type.py?fn=bytes-module/image.png&ct=text/html" with { type: "bytes" };
check(t6, v);
</script>
Original file line number Diff line number Diff line change
@@ -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}`);
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os

from wptserve.utils import isomorphic_decode

def main(request, response):
directory = os.path.dirname(isomorphic_decode(__file__))

try:
file_name = request.GET.first(b"fn")
content_type = request.GET.first(b"ct")
with open(os.path.join(directory, isomorphic_decode(file_name)), u"rb") as fh:
content = fh.read()

response.headers.set(b"Content-Type", content_type)
response.content = content
except:
response.set_error(400, u"Not enough parameters or file not found")
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Bytes modules</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script>
const t = async_test();
</script>
<script type="module" onerror="t.step(() => assert_unreached(event))">
import v from "./image.png" with { type: "bytes" };
t.step(() => {
assert_true(v instanceof Uint8Array);
const expected = [
0x89,
0x50,
0x4e,
0x47,
0xd,
0xa,
0x1a,
0xa,
0x0,
0x0,
0x0,
0xd,
0x49,
0x48,
0x44,
0x52,
0x0,
0x0,
0x0,
0x1,
0x0,
0x0,
0x0,
0x1,
0x1,
0x0,
0x0,
0x0,
0x0,
0x37,
0x6e,
0xf9,
0x24,
0x0,
0x0,
0x0,
0xa,
0x49,
0x44,
0x41,
0x54,
0x78,
0x1,
0x63,
0x60,
0x0,
0x0,
0x0,
0x2,
0x0,
0x1,
0x73,
0x75,
0x1,
0x18,
0x0,
0x0,
0x0,
0x0,
0x49,
0x45,
0x4e,
0x44,
0xae,
0x42,
0x60,
0x82,
];
assert_array_equals(Array.from(v), expected);
t.done();
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "data": "�湿�" }