Skip to content

Fix ECMA 262 \Z and \z tests #427

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion tests/draft2019-09/optional/ecmascript-regex.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,46 @@
"schema": { "format": "regex" },
"tests": [
{
"description": "ECMA 262 has no support for \\Z anchor from .NET",
"description": "ECMA 262 has no support for \\Z anchor, but it's still a valid regex",
"data": "^\\S(|(.|\\n)*\\S)\\Z",
"valid": true
}
]
},
{
"description": "ECMA 262 regex non-compliance",
"schema": {
"type": "string",
"pattern": "^x\\Z"
},
"tests": [
{
"description": "\\Z should match literal Z",
Copy link
Member

@ChALkeR ChALkeR Aug 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that \Z should match literal Z is always correct, so I would argue that it's not justified here.

\Z (and other unsupported flags) behavior differs in ECMA 262 RegExp depending on the mode.
It's not a valid regexp with u flag:

> /Z/.test('Z')
true
> /\Z/.test('Z')
true
> /Z/u.test('Z')
true
> /\Z/u.test('Z')
Thrown:
SyntaxError: Invalid regular expression: /\Z/: Invalid escape

Moreover, other tests here imply that pattern matching should be run in unicode mode, which is incompatible with this test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you suggest the change, then? I was going by regex101.com.

"data": "xZ",
"valid": true
},
{
"description": "\\Z should not match end",
"data": "x",
"valid": false
}
]
},
{
"description": "ECMA 262 regex non-compliance",
"schema": {
"type": "string",
"pattern": "^x\\z"
},
"tests": [
{
"description": "\\z should match literal z",
"data": "xz",
"valid": true
},
{
"description": "\\z should not match end",
"data": "x",
"valid": false
}
]
Expand Down