LibJS: Keep escaping forward slashes

Reverts 5dce916a50.

Now:

    > new RegExp('/').source
    "\/"

This matches spec (and v8).
This commit is contained in:
Nico Weber 2023-02-15 08:20:52 -05:00 committed by Linus Groh
parent eb27b397b8
commit 3c8bfa4662
Notes: sideshowbarker 2024-07-17 00:24:16 +09:00

View File

@ -249,7 +249,7 @@ DeprecatedString RegExpObject::escape_regexp_pattern() const
if (m_pattern.is_empty())
return "(?:)";
// FIXME: Check the 'u' and 'v' flags and escape accordingly
return m_pattern.replace("\n"sv, "\\n"sv, ReplaceMode::All).replace("\r"sv, "\\r"sv, ReplaceMode::All).replace(LINE_SEPARATOR_STRING, "\\u2028"sv, ReplaceMode::All).replace(PARAGRAPH_SEPARATOR_STRING, "\\u2029"sv, ReplaceMode::All);
return m_pattern.replace("\n"sv, "\\n"sv, ReplaceMode::All).replace("\r"sv, "\\r"sv, ReplaceMode::All).replace(LINE_SEPARATOR_STRING, "\\u2028"sv, ReplaceMode::All).replace(PARAGRAPH_SEPARATOR_STRING, "\\u2029"sv, ReplaceMode::All).replace("/"sv, "\\/"sv, ReplaceMode::All);
}
// 22.2.3.2.4 RegExpCreate ( P, F ), https://tc39.es/ecma262/#sec-regexpcreate