diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-08-11 09:39:10 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-08-15 11:43:45 +0100 |
commit | e887314472b827c4fcdcc22f09aaeaf69e6d2e4c (patch) | |
tree | ab0cf3bcd67f0833ad3f94b0586c2d84016ffed9 /Tests | |
parent | 51b3fb5532e6eb519213450a4cd502a3b05e23ff (diff) | |
download | serenity-e887314472b827c4fcdcc22f09aaeaf69e6d2e4c.zip |
LibRegex: Fix ECMA-262 parsing of invalid identity escapes
* Only alphabetic (A-Z, a-z) characters may be escaped with \c. The loop
currently parsing \c includes code points between the upper/lower case
groups.
* In Unicode mode, all invalid identity escapes should cause a parser
error, even in browser-extended mode.
* Avoid an infinite loop when parsing the pattern "\c" on its own.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/LibRegex/Regex.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Tests/LibRegex/Regex.cpp b/Tests/LibRegex/Regex.cpp index 820d5401fa..fc72472d36 100644 --- a/Tests/LibRegex/Regex.cpp +++ b/Tests/LibRegex/Regex.cpp @@ -525,6 +525,18 @@ TEST_CASE(ECMA262_parse) { "\\\\p{1}", regex::Error::NoError, ECMAScriptFlags::Unicode }, { "\\\\p{AsCiI}", regex::Error::InvalidPattern, ECMAScriptFlags::Unicode }, { "\\\\p{ASCII}", regex::Error::InvalidPattern, ECMAScriptFlags::Unicode }, + { "\\c", regex::Error::NoError, ECMAScriptFlags::BrowserExtended }, + { "\\c", regex::Error::InvalidPattern, ECMAScriptFlags::Unicode }, + { "[\\c]", regex::Error::NoError, ECMAScriptFlags::BrowserExtended }, + { "[\\c]", regex::Error::InvalidPattern, ECMAScriptFlags::Unicode }, + { "\\c`", regex::Error::NoError, ECMAScriptFlags::BrowserExtended }, + { "\\c`", regex::Error::InvalidPattern, ECMAScriptFlags::Unicode }, + { "[\\c`]", regex::Error::NoError, ECMAScriptFlags::BrowserExtended }, + { "[\\c`]", regex::Error::InvalidPattern, ECMAScriptFlags::Unicode }, + { "\\A", regex::Error::NoError, ECMAScriptFlags::BrowserExtended }, + { "\\A", regex::Error::InvalidCharacterClass, ECMAScriptFlags::Unicode }, + { "[\\A]", regex::Error::NoError, ECMAScriptFlags::BrowserExtended }, + { "[\\A]", regex::Error::InvalidPattern, ECMAScriptFlags::Unicode }, }; for (auto& test : tests) { @@ -579,6 +591,7 @@ TEST_CASE(ECMA262_match) { "\\05", "\5", true, ECMAScriptFlags::BrowserExtended }, { "\\455", "\45""5", true, ECMAScriptFlags::BrowserExtended }, { "\\314", "\314", true, ECMAScriptFlags::BrowserExtended }, + { "\\c", "\\c", true, ECMAScriptFlags::BrowserExtended }, { "\\cf", "\06", true, ECMAScriptFlags::BrowserExtended }, { "\\c1", "\\c1", true, ECMAScriptFlags::BrowserExtended }, { "[\\c1]", "\x11", true, ECMAScriptFlags::BrowserExtended }, |