mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:37:35 +00:00
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
This commit is contained in:
parent
e3f3470a6c
commit
b409a40377
1 changed files with 19 additions and 3 deletions
|
@ -266,10 +266,26 @@ DeprecatedString RegExpObject::escape_regexp_pattern() const
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code_point == '\r' || code_point == LINE_SEPARATOR || code_point == PARAGRAPH_SEPARATOR || code_point == '/') {
|
switch (code_point) {
|
||||||
builder.append_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();
|
return builder.to_deprecated_string();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue