Truly independent web browser
LibJS: Reject duplicate import attribute keys
Andreas Kling0973ada269a1
diff --git a/Libraries/LibJS/Rust/src/parser/declarations.rs b/Libraries/LibJS/Rust/src/parser/declarations.rsindex c9a5d04b18f..94da1680569 100644--- a/Libraries/LibJS/Rust/src/parser/declarations.rs+++ b/Libraries/LibJS/Rust/src/parser/declarations.rs@@ -2220,7 +2220,7 @@ impl Parser<'_> {self.consume();self.consume_token(TokenType::CurlyOpen);- let mut attributes = Vec::new();+ let mut attributes: Vec<ImportAttribute> = Vec::new();while !self.done() && !self.match_token(TokenType::CurlyClose) {let key: Utf16String = if self.match_token(TokenType::StringLiteral) {let token = self.consume();@@ -2240,6 +2240,14 @@ impl Parser<'_> {if self.match_token(TokenType::StringLiteral) {let token = self.consume();let (value, _) = self.parse_string_value(&token);++ // https://tc39.es/ecma262/#sec-imports-static-semantics-early-errors+ // It is a Syntax Error if WithClauseToAttributes of WithClause has two different entries a and b such+ // that a.[[Key]] is b.[[Key]].+ if attributes.iter().any(|attribute| attribute.key == key) {+ self.syntax_error("Duplicate import attribute key");+ }+attributes.push(ImportAttribute { key, value });} else {self.expected("string as attribute value");diff --git a/Tests/LibJS/Runtime/modules/basic-modules.js b/Tests/LibJS/Runtime/modules/basic-modules.jsindex 5c2cb071f4b..742d52a5c36 100644--- a/Tests/LibJS/Runtime/modules/basic-modules.js+++ b/Tests/LibJS/Runtime/modules/basic-modules.js@@ -196,6 +196,10 @@ describe("in- and exports", () => {expectModulePassed("./import-with-attributes.mjs");});+ test("import attribute keys must be unique", () => {+ expectedModuleToThrowSyntaxError("./duplicate-import-attribute-key.mjs", "Duplicate import attribute key");+ });+test("namespace has expected ordering", () => {expectModulePassed("./namespace-order.mjs");});diff --git a/Tests/LibJS/Runtime/modules/duplicate-import-attribute-key.mjs b/Tests/LibJS/Runtime/modules/duplicate-import-attribute-key.mjsnew file mode 100644index 00000000000..5b82134e86b--- /dev/null+++ b/Tests/LibJS/Runtime/modules/duplicate-import-attribute-key.mjs@@ -0,0 +1 @@+import "./single-const-export.mjs" with { type: "json", "typ\u0065": "" };