Truly independent web browser
LibWeb: Keep a byte order mark in WebAssembly module names
Shannon Booth9e4ef2254c59
diff --git a/Libraries/LibWeb/WebAssembly/Module.cpp b/Libraries/LibWeb/WebAssembly/Module.cppindex ff03ec57d07..6dfed2234db 100644--- a/Libraries/LibWeb/WebAssembly/Module.cpp+++ b/Libraries/LibWeb/WebAssembly/Module.cpp@@ -74,8 +74,8 @@ WebIDL::ExceptionOr<Vector<Bindings::ModuleImportDescriptor>> Module::imports(GC// 3.2. Let obj be «[ "module" → moduleName, "name" → name, "kind" → kind ]».Bindings::ModuleImportDescriptor descriptor {.kind = kind,- .module = Utf16String::from_utf8_with_replacement_character(import.module()),- .name = Utf16String::from_utf8_with_replacement_character(import.name()),+ .module = Utf16String::from_utf8(import.module()),+ .name = Utf16String::from_utf8(import.name()),};// 3.3. Append obj to imports.@@ -111,7 +111,7 @@ WebIDL::ExceptionOr<Vector<Bindings::ModuleExportDescriptor>> Module::exports(GC// 3.2. Let obj be «[ "name" → name, "kind" → kind ]».Bindings::ModuleExportDescriptor descriptor {.kind = kind,- .name = Utf16String::from_utf8_with_replacement_character(entry.name()),+ .name = Utf16String::from_utf8(entry.name()),};// 3.3. Append obj to exports.export_objects.append(move(descriptor));@@ -126,7 +126,7 @@ WebIDL::ExceptionOr<Vector<ByteBuffer>> Module::custom_sections(GC::Ref<Module>auto& custom_sections = module_object->m_compiled_module->module->custom_sections();for (auto& section : custom_sections) {- auto name = Utf16String::from_utf8_with_replacement_character(section.name());+ auto name = Utf16String::from_utf8(section.name());if (section_name == name)matching_sections.append(MUST(ByteBuffer::copy(section.contents())));}diff --git a/Tests/LibWeb/Text/expected/Wasm/WebAssembly-Module-names-keep-byte-order-mark.txt b/Tests/LibWeb/Text/expected/Wasm/WebAssembly-Module-names-keep-byte-order-mark.txtnew file mode 100644index 00000000000..a8cc2a10080--- /dev/null+++ b/Tests/LibWeb/Text/expected/Wasm/WebAssembly-Module-names-keep-byte-order-mark.txt@@ -0,0 +1,5 @@+import module: true+import name: true+export name: true+custom sections named "\ufeffc": 1+custom sections named "c": 0diff --git a/Tests/LibWeb/Text/input/Wasm/WebAssembly-Module-names-keep-byte-order-mark.html b/Tests/LibWeb/Text/input/Wasm/WebAssembly-Module-names-keep-byte-order-mark.htmlnew file mode 100644index 00000000000..a55fd37618f--- /dev/null+++ b/Tests/LibWeb/Text/input/Wasm/WebAssembly-Module-names-keep-byte-order-mark.html@@ -0,0 +1,32 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ test(() => {+ // Each name starts with U+FEFF (EF BB BF).+ const wasmBytes = new Uint8Array([+ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00,+ // Type section: () -> ()+ 0x01, 0x04, 0x01, 0x60, 0x00, 0x00,+ // Import section: "m" "f" (func 0)+ 0x02, 0x0d, 0x01, 0x04, 0xef, 0xbb, 0xbf, 0x6d, 0x04, 0xef, 0xbb, 0xbf, 0x66, 0x00, 0x00,+ // Function section+ 0x03, 0x02, 0x01, 0x00,+ // Export section: "e" (func 1)+ 0x07, 0x08, 0x01, 0x04, 0xef, 0xbb, 0xbf, 0x65, 0x00, 0x01,+ // Code section+ 0x0a, 0x04, 0x01, 0x02, 0x00, 0x0b,+ // Custom section: "c"+ 0x00, 0x05, 0x04, 0xef, 0xbb, 0xbf, 0x63,+ ]);++ const module = new WebAssembly.Module(wasmBytes);+ const [importDescriptor] = WebAssembly.Module.imports(module);+ const [exportDescriptor] = WebAssembly.Module.exports(module);++ println(`import module: ${importDescriptor.module === "m"}`);+ println(`import name: ${importDescriptor.name === "f"}`);+ println(`export name: ${exportDescriptor.name === "e"}`);+ println(`custom sections named "\\ufeffc": ${WebAssembly.Module.customSections(module, "c").length}`);+ println(`custom sections named "c": ${WebAssembly.Module.customSections(module, "c").length}`);+ });+</script>