diff --git a/test/built-ins/RegExp/named-groups/string-replace-missing.js b/test/built-ins/RegExp/named-groups/string-replace-missing.js index 6d253568c2..dff67e69b3 100644 --- a/test/built-ins/RegExp/named-groups/string-replace-missing.js +++ b/test/built-ins/RegExp/named-groups/string-replace-missing.js @@ -2,24 +2,23 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -description: SyntaxError is thrown for malformed replacements +description: If the group doesn't exist, replace with the empty string esid: sec-getsubstitution features: [regexp-named-groups] -info: > - Runtime Semantics: GetSubstitution( matched, str, position, captures, namedCaptures, replacement ) - - Table: Replacement Text Symbol Substitutions - - Unicode Characters: $< - Replacement text: - 2. Otherwise, - b. If ? HasProperty(namedCaptures, groupName) is false, throw a SyntaxError exception. ---*/ let source = "(?.)(?.)|(?x)"; -for (let flags of ["", "u", "g", "gu"]) { +for (let flags of ["", "u"]) { let re = new RegExp(source, flags); - assert.throws(SyntaxError, () => "abcd".replace(re, "$<42$1>")); - assert.throws(SyntaxError, () => "abcd".replace(re, "$")); - assert.throws(SyntaxError, () => "abcd".replace(re, "$<$1>")); + assert.sameValue("cd", "abcd".replace(re, "$<42$1>")); + assert.sameValue("cd", "abcd".replace(re, "$")); + assert.sameValue("cd", "abcd".replace(re, "$<$1>")); + assert.sameValue("cd", "abcd".replace(re, "$<>")); +} +for (let flags of ["g", "gu"]) { + let re = new RegExp(source, flags); + assert.sameValue("", "abcd".replace(re, "$<42$1>")); + assert.sameValue("", "abcd".replace(re, "$")); + assert.sameValue("", "abcd".replace(re, "$<$1>")); + assert.sameValue("", "abcd".replace(re, "$<>")); } diff --git a/test/built-ins/RegExp/named-groups/string-replace-nocaptures.js b/test/built-ins/RegExp/named-groups/string-replace-nocaptures.js index 39a5887069..e0f1ceec0b 100644 --- a/test/built-ins/RegExp/named-groups/string-replace-nocaptures.js +++ b/test/built-ins/RegExp/named-groups/string-replace-nocaptures.js @@ -24,6 +24,7 @@ for (let flags of ["", "u"]) { assert.sameValue("bacd", "abcd".replace(re, "$2$1")); assert.sameValue("cd", "abcd".replace(re, "$3")); assert.sameValue("$cd", "abcd".replace(re, "$<42$1>")); assert.sameValue("$cd", "abcd".replace(re, "$")); assert.sameValue("$cd", "abcd".replace(re, "$<$1>")); diff --git a/test/built-ins/RegExp/named-groups/string-replace-unclosed.js b/test/built-ins/RegExp/named-groups/string-replace-unclosed.js index 1952b85050..0cec59b218 100644 --- a/test/built-ins/RegExp/named-groups/string-replace-unclosed.js +++ b/test/built-ins/RegExp/named-groups/string-replace-unclosed.js @@ -2,25 +2,18 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -description: SyntaxError is thrown for malformed replacements +description: A missing > following $< means that the $< is taken literally + in a replacement string in the context of named capture substitution. esid: sec-getsubstitution features: [regexp-named-groups] -info: > - Runtime Semantics: GetSubstitution( matched, str, position, captures, namedCaptures, replacement ) - - Table: Replacement Text Symbol Substitutions - - Unicode Characters: $< - Replacement text: - 2. Otherwise, - a. Scan until the next >, throwing a SyntaxError exception if one is not found, and let the enclosed substring be groupName. ---*/ let source = "(?.)(?.)|(?x)"; -for (let flags of ["", "u", "g", "gu"]) { +for (let flags of ["", "u"]) { let re = new RegExp(source, flags); - assert.throws(SyntaxError, () => "abcd".replace(re, "$ "abcd".replace(re, "$<>"), - "empty named group in replacement should throw a SyntaxError"); + assert.sameValue("$