summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2023-02-17 01:13:33 +0330
committerLinus Groh <mail@linusgroh.de>2023-02-16 23:32:35 +0100
commitb409a40377b9b3a22155293f320420cebeea12cf (patch)
treeaf8811db22ea11ba5d19925b607b0f14333cb7dc /Userland/Libraries/LibJS
parente3f3470a6c41afc33084756de4e8bdecfe7acaa2 (diff)
downloadserenity-b409a40377b9b3a22155293f320420cebeea12cf.zip
LibJS: Actually escape \n|\r|LS|PS when escaping RegExp.source
We were previously encoding them as `\<literal newline>`, which is just all sorts of wrong :P
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpObject.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp
index 40c7a6638f..955e18e879 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp
@@ -266,10 +266,26 @@ DeprecatedString RegExpObject::escape_regexp_pattern() const
continue;
}
- if (code_point == '\r' || code_point == LINE_SEPARATOR || code_point == PARAGRAPH_SEPARATOR || code_point == '/') {
- builder.append_code_point('\\');
+ switch (code_point) {
+ case '/':
+ builder.append("\\/"sv);
+ break;
+ case '\n':
+ builder.append("\\n"sv);
+ break;
+ case '\r':
+ builder.append("\\r"sv);
+ break;
+ case LINE_SEPARATOR:
+ builder.append("\\u2028"sv);
+ break;
+ case PARAGRAPH_SEPARATOR:
+ builder.append("\\u2029"sv);
+ break;
+ default:
+ builder.append_code_point(code_point);
+ break;
}
- builder.append_code_point(code_point);
}
return builder.to_deprecated_string();