From 3c8bfa46626594c126f2835090e84ac5bb51167b Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 15 Feb 2023 08:20:52 -0500 Subject: [PATCH] LibJS: Keep escaping forward slashes Reverts 5dce916a504. Now: > new RegExp('/').source "\/" This matches spec (and v8). --- Userland/Libraries/LibJS/Runtime/RegExpObject.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp index 07d563480d0..74b52e30004 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp @@ -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