-
Notifications
You must be signed in to change notification settings - Fork 97
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
Regex patterns lose escape characters #378
Comments
This also causes another bug I have, the \n and \r characters (linebreak and carriage return) are parsed as-is, introducing newlines in the generating file, causing syntax errors. |
EDIT: They are not. They are now encapsulated in backticks (`) which resolves the syntax error, but still isn't what I want: Spec: {
"expressionSyntax": {
"type": "string",
"$comment": "escape `{` and `}` in pattern to be unicode compatible",
"pattern": "^\\$\\{\\{(.|[\r\n])*\\}\\}$"
}
} Generated: // UnmarshalJSON implements json.Unmarshaler.
func (j *ExpressionSyntax) UnmarshalJSON(b []byte) error {
type Plain ExpressionSyntax
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
if matched, _ := regexp.MatchString(`^\$\{\{(.|[
])*\}\}$`, string(plain)); !matched {
return fmt.Errorf("field %s pattern match: must match %s", "", `^\$\{\{(.|[
])*\}\}$`)
}
*j = ExpressionSyntax(plain)
return nil
} |
So I'm working on this now, but I think the generated output is correct; The error you were getting was likely due to the string being written with double quotes ( I've added a testcase, just in case, as well as fixed my newline / linefeed issue, in this PR: https://github.com/omissis/go-jsonschema/pull/380/files#diff-0f1966ad78d962abdb496073e8f7c44a8d98ed6916437fef88284a571388f6be |
I was using v0.17.0 but it's working for me on main. Doesn't look like the url made any difference |
I'm trying to generate the devContainer.base.json schema with the following:
The schema contains the following spec:
Which is generated as:
Resulting in an "unknown escape sequence" error for
\d
The text was updated successfully, but these errors were encountered: