-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Correct Regular Expressions Behavior Related to Annex B #58320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rbuckton
merged 12 commits into
microsoft:main
from
graphemecluster:regex-syntax-check-annexB
May 29, 2024
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e049438
Correct RegExp Behavior Related to Annex B
graphemecluster 358eb30
Fix Comment
graphemecluster 8facb0a
Correct Quantifiability of `{1` in Annex B
graphemecluster f5c0b60
`\c` is an Annex B thing
graphemecluster cff993f
Add Tests
graphemecluster 603c3cf
Merge from main
rbuckton 2e62d25
Apply Suggested Changes
graphemecluster ed08ef7
Apply Suggested Changes
graphemecluster 8b67d77
Merge branch 'main' into regex-syntax-check-annexB
graphemecluster b48f0d0
Provide User-Friendly Errors for Decimal Escapes Inside Character Cla…
graphemecluster c72f92f
Fix Behavior Related to `namedCaptureGroups`
graphemecluster 70a3214
Clarify why nested character classes should not be considered in the …
graphemecluster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
266 changes: 266 additions & 0 deletions
266
tests/baselines/reference/regularExpressionAnnexB.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,266 @@ | ||
| regularExpressionAnnexB.ts(2,8): error TS1125: Hexadecimal digit expected. | ||
| regularExpressionAnnexB.ts(2,22): error TS1125: Hexadecimal digit expected. | ||
| regularExpressionAnnexB.ts(2,28): error TS1125: Hexadecimal digit expected. | ||
| regularExpressionAnnexB.ts(3,9): error TS1125: Hexadecimal digit expected. | ||
| regularExpressionAnnexB.ts(3,23): error TS1125: Hexadecimal digit expected. | ||
| regularExpressionAnnexB.ts(3,29): error TS1125: Hexadecimal digit expected. | ||
| regularExpressionAnnexB.ts(7,4): error TS1535: This character cannot be escaped in a regular expression. | ||
| regularExpressionAnnexB.ts(7,8): error TS1125: Hexadecimal digit expected. | ||
| regularExpressionAnnexB.ts(7,10): error TS1512: '\c' must be followed by an ASCII letter. | ||
| regularExpressionAnnexB.ts(7,14): error TS1535: This character cannot be escaped in a regular expression. | ||
| regularExpressionAnnexB.ts(7,18): error TS1535: This character cannot be escaped in a regular expression. | ||
| regularExpressionAnnexB.ts(7,22): error TS1125: Hexadecimal digit expected. | ||
| regularExpressionAnnexB.ts(7,24): error TS1535: This character cannot be escaped in a regular expression. | ||
| regularExpressionAnnexB.ts(7,28): error TS1125: Hexadecimal digit expected. | ||
| regularExpressionAnnexB.ts(7,30): error TS1531: '\p' must be followed by a Unicode property value expression enclosed in braces. | ||
| regularExpressionAnnexB.ts(8,5): error TS1535: This character cannot be escaped in a regular expression. | ||
| regularExpressionAnnexB.ts(8,9): error TS1125: Hexadecimal digit expected. | ||
| regularExpressionAnnexB.ts(8,11): error TS1512: '\c' must be followed by an ASCII letter. | ||
| regularExpressionAnnexB.ts(8,13): error TS1535: This character cannot be escaped in a regular expression. | ||
| regularExpressionAnnexB.ts(8,15): error TS1535: This character cannot be escaped in a regular expression. | ||
| regularExpressionAnnexB.ts(8,19): error TS1535: This character cannot be escaped in a regular expression. | ||
| regularExpressionAnnexB.ts(8,23): error TS1125: Hexadecimal digit expected. | ||
| regularExpressionAnnexB.ts(8,25): error TS1535: This character cannot be escaped in a regular expression. | ||
| regularExpressionAnnexB.ts(8,29): error TS1125: Hexadecimal digit expected. | ||
| regularExpressionAnnexB.ts(8,31): error TS1531: '\p' must be followed by a Unicode property value expression enclosed in braces. | ||
| regularExpressionAnnexB.ts(9,4): error TS1531: '\P' must be followed by a Unicode property value expression enclosed in braces. | ||
| regularExpressionAnnexB.ts(9,7): error TS1531: '\P' must be followed by a Unicode property value expression enclosed in braces. | ||
| regularExpressionAnnexB.ts(9,9): error TS1516: A character class range must not be bounded by another character class. | ||
| regularExpressionAnnexB.ts(23,4): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(23,8): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(24,4): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(24,9): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(25,4): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(25,10): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(26,4): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(26,5): error TS1506: Numbers out of order in quantifier. | ||
| regularExpressionAnnexB.ts(26,10): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(29,4): error TS1508: Unexpected '{'. Did you mean to escape it with backslash? | ||
| regularExpressionAnnexB.ts(30,4): error TS1508: Unexpected '{'. Did you mean to escape it with backslash? | ||
| regularExpressionAnnexB.ts(31,4): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(31,5): error TS1505: Incomplete quantifier. Digit expected. | ||
| regularExpressionAnnexB.ts(31,7): error TS1005: '}' expected. | ||
| regularExpressionAnnexB.ts(31,8): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(32,4): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(32,6): error TS1005: '}' expected. | ||
| regularExpressionAnnexB.ts(32,7): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(33,4): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(33,7): error TS1005: '}' expected. | ||
| regularExpressionAnnexB.ts(33,8): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(34,4): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(34,8): error TS1005: '}' expected. | ||
| regularExpressionAnnexB.ts(34,9): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(35,4): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(35,5): error TS1506: Numbers out of order in quantifier. | ||
| regularExpressionAnnexB.ts(35,8): error TS1005: '}' expected. | ||
| regularExpressionAnnexB.ts(35,9): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(36,4): error TS1508: Unexpected '{'. Did you mean to escape it with backslash? | ||
| regularExpressionAnnexB.ts(36,5): error TS1508: Unexpected '}'. Did you mean to escape it with backslash? | ||
| regularExpressionAnnexB.ts(37,4): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(37,5): error TS1505: Incomplete quantifier. Digit expected. | ||
| regularExpressionAnnexB.ts(37,8): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(38,4): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(38,5): error TS1505: Incomplete quantifier. Digit expected. | ||
| regularExpressionAnnexB.ts(38,9): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(39,4): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(39,8): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(40,4): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(40,9): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(41,4): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(41,10): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(42,4): error TS1507: There is nothing available for repetition. | ||
| regularExpressionAnnexB.ts(42,5): error TS1506: Numbers out of order in quantifier. | ||
| regularExpressionAnnexB.ts(42,10): error TS1507: There is nothing available for repetition. | ||
|
|
||
|
|
||
| ==== regularExpressionAnnexB.ts (73 errors) ==== | ||
| const regexes: RegExp[] = [ | ||
| /\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s/, | ||
|
|
||
| !!! error TS1125: Hexadecimal digit expected. | ||
|
|
||
| !!! error TS1125: Hexadecimal digit expected. | ||
|
|
||
| !!! error TS1125: Hexadecimal digit expected. | ||
| /[\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s]/, | ||
|
|
||
| !!! error TS1125: Hexadecimal digit expected. | ||
|
|
||
| !!! error TS1125: Hexadecimal digit expected. | ||
|
|
||
| !!! error TS1125: Hexadecimal digit expected. | ||
| /\P[\P\w-_]/, | ||
|
|
||
| // Compare to | ||
| /\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s/u, | ||
| ~~ | ||
| !!! error TS1535: This character cannot be escaped in a regular expression. | ||
|
|
||
| !!! error TS1125: Hexadecimal digit expected. | ||
| ~~ | ||
| !!! error TS1512: '\c' must be followed by an ASCII letter. | ||
| ~~ | ||
| !!! error TS1535: This character cannot be escaped in a regular expression. | ||
| ~~ | ||
| !!! error TS1535: This character cannot be escaped in a regular expression. | ||
|
|
||
| !!! error TS1125: Hexadecimal digit expected. | ||
| ~~ | ||
| !!! error TS1535: This character cannot be escaped in a regular expression. | ||
|
|
||
| !!! error TS1125: Hexadecimal digit expected. | ||
| ~~ | ||
| !!! error TS1531: '\p' must be followed by a Unicode property value expression enclosed in braces. | ||
| /[\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s]/u, | ||
| ~~ | ||
| !!! error TS1535: This character cannot be escaped in a regular expression. | ||
|
|
||
| !!! error TS1125: Hexadecimal digit expected. | ||
| ~~ | ||
| !!! error TS1512: '\c' must be followed by an ASCII letter. | ||
| ~~ | ||
| !!! error TS1535: This character cannot be escaped in a regular expression. | ||
| ~~ | ||
| !!! error TS1535: This character cannot be escaped in a regular expression. | ||
| ~~ | ||
| !!! error TS1535: This character cannot be escaped in a regular expression. | ||
|
|
||
| !!! error TS1125: Hexadecimal digit expected. | ||
| ~~ | ||
| !!! error TS1535: This character cannot be escaped in a regular expression. | ||
|
|
||
| !!! error TS1125: Hexadecimal digit expected. | ||
| ~~ | ||
| !!! error TS1531: '\p' must be followed by a Unicode property value expression enclosed in braces. | ||
| /\P[\P\w-_]/u, | ||
| ~~ | ||
| !!! error TS1531: '\P' must be followed by a Unicode property value expression enclosed in braces. | ||
| ~~ | ||
| !!! error TS1531: '\P' must be followed by a Unicode property value expression enclosed in braces. | ||
| ~~ | ||
| !!! error TS1516: A character class range must not be bounded by another character class. | ||
| ]; | ||
|
|
||
| const regexesWithBraces: RegExp[] = [ | ||
| /{??/, | ||
| /{,??/, | ||
| /{,1??/, | ||
| /{1??/, | ||
| /{1,??/, | ||
| /{1,2??/, | ||
| /{2,1??/, | ||
| /{}??/, | ||
| /{,}??/, | ||
| /{,1}??/, | ||
| /{1}??/, | ||
| ~~~~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| ~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| /{1,}??/, | ||
| ~~~~~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| ~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| /{1,2}??/, | ||
| ~~~~~~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| ~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| /{2,1}??/, | ||
| ~~~~~~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| ~~~ | ||
| !!! error TS1506: Numbers out of order in quantifier. | ||
| ~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
|
|
||
| // Compare to | ||
| /{??/u, | ||
| ~ | ||
| !!! error TS1508: Unexpected '{'. Did you mean to escape it with backslash? | ||
| /{,??/u, | ||
| ~ | ||
| !!! error TS1508: Unexpected '{'. Did you mean to escape it with backslash? | ||
| /{,1??/u, | ||
| ~~~~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
|
|
||
| !!! error TS1505: Incomplete quantifier. Digit expected. | ||
|
|
||
| !!! error TS1005: '}' expected. | ||
| ~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| /{1??/u, | ||
| ~~~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
|
|
||
| !!! error TS1005: '}' expected. | ||
| ~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| /{1,??/u, | ||
| ~~~~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
|
|
||
| !!! error TS1005: '}' expected. | ||
| ~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| /{1,2??/u, | ||
| ~~~~~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
|
|
||
| !!! error TS1005: '}' expected. | ||
| ~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| /{2,1??/u, | ||
| ~~~~~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| ~~~ | ||
| !!! error TS1506: Numbers out of order in quantifier. | ||
|
|
||
| !!! error TS1005: '}' expected. | ||
| ~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| /{}??/u, | ||
| ~ | ||
| !!! error TS1508: Unexpected '{'. Did you mean to escape it with backslash? | ||
| ~ | ||
| !!! error TS1508: Unexpected '}'. Did you mean to escape it with backslash? | ||
| /{,}??/u, | ||
| ~~~~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
|
|
||
| !!! error TS1505: Incomplete quantifier. Digit expected. | ||
| ~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| /{,1}??/u, | ||
| ~~~~~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
|
|
||
| !!! error TS1505: Incomplete quantifier. Digit expected. | ||
| ~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| /{1}??/u, | ||
| ~~~~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| ~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| /{1,}??/u, | ||
| ~~~~~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| ~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| /{1,2}??/u, | ||
| ~~~~~~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| ~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| /{2,1}??/u, | ||
| ~~~~~~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| ~~~ | ||
| !!! error TS1506: Numbers out of order in quantifier. | ||
| ~ | ||
| !!! error TS1507: There is nothing available for repetition. | ||
| ]; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| //// [tests/cases/compiler/regularExpressionAnnexB.ts] //// | ||
|
|
||
| //// [regularExpressionAnnexB.ts] | ||
| const regexes: RegExp[] = [ | ||
| /\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s/, | ||
| /[\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s]/, | ||
| /\P[\P\w-_]/, | ||
|
|
||
| // Compare to | ||
| /\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s/u, | ||
| /[\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s]/u, | ||
| /\P[\P\w-_]/u, | ||
| ]; | ||
|
|
||
| const regexesWithBraces: RegExp[] = [ | ||
| /{??/, | ||
| /{,??/, | ||
| /{,1??/, | ||
| /{1??/, | ||
| /{1,??/, | ||
| /{1,2??/, | ||
| /{2,1??/, | ||
| /{}??/, | ||
| /{,}??/, | ||
| /{,1}??/, | ||
| /{1}??/, | ||
| /{1,}??/, | ||
| /{1,2}??/, | ||
| /{2,1}??/, | ||
|
|
||
| // Compare to | ||
| /{??/u, | ||
| /{,??/u, | ||
| /{,1??/u, | ||
| /{1??/u, | ||
| /{1,??/u, | ||
| /{1,2??/u, | ||
| /{2,1??/u, | ||
| /{}??/u, | ||
| /{,}??/u, | ||
| /{,1}??/u, | ||
| /{1}??/u, | ||
| /{1,}??/u, | ||
| /{1,2}??/u, | ||
| /{2,1}??/u, | ||
| ]; | ||
|
|
||
|
|
||
| //// [regularExpressionAnnexB.js] | ||
| const regexes = [ | ||
| /\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s/, | ||
| /[\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s]/, | ||
| /\P[\P\w-_]/, | ||
| // Compare to | ||
| /\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s/u, | ||
| /[\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s]/u, | ||
| /\P[\P\w-_]/u, | ||
| ]; | ||
| const regexesWithBraces = [ | ||
| /{??/, | ||
| /{,??/, | ||
| /{,1??/, | ||
| /{1??/, | ||
| /{1,??/, | ||
| /{1,2??/, | ||
| /{2,1??/, | ||
| /{}??/, | ||
| /{,}??/, | ||
| /{,1}??/, | ||
| /{1}??/, | ||
| /{1,}??/, | ||
| /{1,2}??/, | ||
| /{2,1}??/, | ||
| // Compare to | ||
| /{??/u, | ||
| /{,??/u, | ||
| /{,1??/u, | ||
| /{1??/u, | ||
| /{1,??/u, | ||
| /{1,2??/u, | ||
| /{2,1??/u, | ||
| /{}??/u, | ||
| /{,}??/u, | ||
| /{,1}??/u, | ||
| /{1}??/u, | ||
| /{1,}??/u, | ||
| /{1,2}??/u, | ||
| /{2,1}??/u, | ||
| ]; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are all valid in Annex B. Even
/\u{1/is. In Annex B essentially all weird things are valid, you know. Currently (after #58295)/[\1]/is valid but/[\8]/isn’t. I don’t think it’s ideal.