Skip to content
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

Azure pipelines invalid escape #328

Open
bdovaz opened this issue Jun 21, 2023 · 3 comments
Open

Azure pipelines invalid escape #328

bdovaz opened this issue Jun 21, 2023 · 3 comments

Comments

@bdovaz
Copy link

bdovaz commented Jun 21, 2023

@chris48s I don't understand what is going on, I don't know if the error is in my file or in the schema itself (the url you mention).

My azure-pipelines.yml file should not be because it validates and runs correctly in Azure DevOps.

ℹ Processing .\azure-pipelines.yml
ℹ Found schema in .v8rrc.yml ...
ℹ Validating .\azure-pipelines.yml against schema from https://raw.githubusercontent.com/microsoft/azure-pipelines-vscode/master/service-schema.json ...
✖ Invalid regular expression: /^[^\/~\^\: \[\]\\]+(\/[^\/~\^\: \[\]\\]+)*$/: Invalid escape
@chris48s
Copy link
Owner

It is an error thrown by ajv trying to load the schema.

This can be reproduced independently of v8r, just using ajv-cli:

$ curl "https://raw.githubusercontent.com/microsoft/azure-pipelines-vscode/master/service-schema.json" --output service-schema.json

...

$ npx ajv-cli@latest compile -s service-schema.json
schema service-schema.json is invalid

It is hitting the error on this line of the schema https://github.com/microsoft/azure-pipelines-vscode/blob/97f39ff988232860b35556dde725d448151ec5a0/service-schema.json#L1076 I'm not sure if its an issue with the schema itself or AJV.

@bdovaz
Copy link
Author

bdovaz commented Jun 26, 2023

Created an issue: ajv-validator/ajv#2296

@chris48s
Copy link
Owner

I was working on something else recently that made me realise what is going on here.

AJV constructs regular expressions with the unicode u flag, as required by the spec: https://json-schema.org/understanding-json-schema/reference/string.html#regular-expressions JSON Schema regular expressions are unicode-aware.

In javascript, Unnecessary escape sequences are invalid with the u flag.

So this

var regex = new RegExp("^[^\\/~\\^\\: \\[\\]\\\\]+(\\/[^\\/~\\^\\: \\[\\]\\\\]+)*$", "u")

throws a

Uncaught:
SyntaxError: Invalid regular expression: /^[^\/~\^\: \[\]\\]+(\/[^\/~\^\: \[\]\\]+)*$/: Invalid escape

I guess the reason this schema works with some validators is that maybe there are some JSON schema tools that either don't construct with the unicode flag, or this constraint (no unnecessary escape sequences when using unicode) is not there in other regexp engines. I've not really dug into it. Note that

var regex = new RegExp("^[^\\/~\\^\\: \\[\\]\\\\]+(\\/[^\\/~\\^\\: \\[\\]\\\\]+)*$")

constructs a regex without error.

I think the solution to this - if you wanted to submit a PR upstream to https://github.com/microsoft/azure-pipelines-vscode/ - would be to remove the unnecessary escapes on the : characters.

var regex = new RegExp("^[^\\/~\\^: \\[\\]\\\\]+(\\/[^\\/~\\^: \\[\\]\\\\]+)*$", "u")

is valid with the unicode flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants