mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-30 05:31:10 +00:00
Regexp.prototype.source get error result
Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IB0NG2 Signed-off-by: hecunmao <hecunmao@huawei.com> Change-Id: Ia5b4f03e2259596afd189a0db541102bdb3cd04d
This commit is contained in:
parent
29ed61f07d
commit
3c890df522
@ -2431,11 +2431,17 @@ EcmaString *BuiltinsRegExp::EscapeRegExpPattern(JSThread *thread, const JSHandle
|
||||
if (srcStdStr.empty()) {
|
||||
srcStdStr = "(?:)";
|
||||
}
|
||||
// "/" -> "\/"
|
||||
srcStdStr = base::StringHelper::ReplaceAll(srcStdStr, "/", "\\/");
|
||||
// "\\" -> "\"
|
||||
srcStdStr = base::StringHelper::ReplaceAll(srcStdStr, "\\", "\\");
|
||||
|
||||
bool escapeChar = false;
|
||||
for (int i = 0; i < srcStdStr.size(); i++) {
|
||||
if (srcStdStr[i] == '\\') {
|
||||
escapeChar=!escapeChar;
|
||||
} else if (!escapeChar && srcStdStr[i]=='/') {
|
||||
srcStdStr.insert(i, "\\");
|
||||
i++;
|
||||
} else {
|
||||
escapeChar = false;
|
||||
}
|
||||
}
|
||||
return *factory->NewFromUtf8(srcStdStr);
|
||||
}
|
||||
|
||||
|
@ -176,3 +176,19 @@ gs
|
||||
gu
|
||||
dg
|
||||
g
|
||||
\/ ["/"]
|
||||
\/[a-z]*> ["/style>"]
|
||||
\/[a-z]*> ["/style>"]
|
||||
\/[a-z]*> ["/style>"]
|
||||
\\\/[a-z]*> ["\\/style>"]
|
||||
\\\/[a-z]*> ["\\/style>"]
|
||||
\\\/[a-z]*> ["\\/style>"]
|
||||
\\\/[a-z]*> ["\\/style>"]
|
||||
SyntaxError
|
||||
SyntaxError
|
||||
\[ ["["]
|
||||
\[ ["["]
|
||||
SyntaxError
|
||||
SyntaxError
|
||||
\\\[ ["\\["]
|
||||
\\\[ ["\\["]
|
@ -726,3 +726,90 @@ print(res7.flags);
|
||||
const res8 = /abc/;
|
||||
res8.lastIndex = -1;
|
||||
print(res8.flags);
|
||||
|
||||
{
|
||||
let str = "<style>test</style>"
|
||||
let reg = new RegExp("/");
|
||||
print(reg.source,JSON.stringify(reg.exec(str)));
|
||||
|
||||
reg = new RegExp("\/[a-z]*>");
|
||||
print(reg.source,JSON.stringify(reg.exec(str)));
|
||||
|
||||
reg = new RegExp("\\/[a-z]*>");
|
||||
print(reg.source,JSON.stringify(reg.exec(str)));
|
||||
|
||||
reg = new RegExp("\\\/[a-z]*>");
|
||||
print(reg.source,JSON.stringify(reg.exec(str)));
|
||||
|
||||
str="<style>test<\\\\/style>"
|
||||
reg = new RegExp("\\\\/[a-z]*>");
|
||||
print(reg.source,JSON.stringify(reg.exec(str)));
|
||||
|
||||
reg = new RegExp("\\\\\/[a-z]*>");
|
||||
print(reg.source,JSON.stringify(reg.exec(str)));
|
||||
|
||||
reg = new RegExp("\\\\\\/[a-z]*>");
|
||||
print(reg.source,JSON.stringify(reg.exec(str)));
|
||||
|
||||
reg = new RegExp("\\\\\\\/[a-z]*>");
|
||||
print(reg.source,JSON.stringify(reg.exec(str)));
|
||||
}
|
||||
{
|
||||
let str="\\\\\\\\[aaa"
|
||||
try {
|
||||
let pattern="[";
|
||||
let reg = new RegExp(pattern);
|
||||
print(pattern,JSON.stringify(reg.exec(str)))
|
||||
} catch (e) {
|
||||
print(e.name);
|
||||
}
|
||||
try {
|
||||
let pattern="\[";
|
||||
let reg = new RegExp(pattern);
|
||||
print(pattern,JSON.stringify(reg.exec(str)))
|
||||
} catch (e) {
|
||||
print(e.name);
|
||||
}
|
||||
try {
|
||||
let pattern="\\[";
|
||||
let reg = new RegExp(pattern);
|
||||
print(pattern,JSON.stringify(reg.exec(str)))
|
||||
} catch (e) {
|
||||
print(e.name);
|
||||
}
|
||||
try {
|
||||
let pattern="\\\[";
|
||||
let reg = new RegExp(pattern);
|
||||
print(pattern,JSON.stringify(reg.exec(str)))
|
||||
} catch (e) {
|
||||
print(e.name);
|
||||
}
|
||||
try {
|
||||
let pattern="\\\\[";
|
||||
let reg = new RegExp(pattern);
|
||||
print(pattern,JSON.stringify(reg.exec(str)))
|
||||
} catch (e) {
|
||||
print(e.name);
|
||||
}
|
||||
try {
|
||||
let pattern="\\\\\[";
|
||||
let reg = new RegExp(pattern);
|
||||
print(pattern,JSON.stringify(reg.exec(str)))
|
||||
} catch (e) {
|
||||
print(e.name);
|
||||
}
|
||||
try {
|
||||
let pattern="\\\\\\[";
|
||||
let reg = new RegExp(pattern);
|
||||
print(pattern,JSON.stringify(reg.exec(str)))
|
||||
} catch (e) {
|
||||
print(e.name);
|
||||
}
|
||||
try {
|
||||
let pattern="\\\\\\\[";
|
||||
let reg = new RegExp(pattern);
|
||||
print(pattern,JSON.stringify(reg.exec(str)))
|
||||
} catch (e) {
|
||||
print(e.name);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user