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

Need to preperly escape regexp pattern #21

Open
Pilatuz opened this issue Oct 11, 2021 · 1 comment
Open

Need to preperly escape regexp pattern #21

Pilatuz opened this issue Oct 11, 2021 · 1 comment

Comments

@Pilatuz
Copy link

Pilatuz commented Oct 11, 2021

The code generator is unable to handle the following regexp pattern:

"name": {
  "type": "string",
  "pattern": "^[0-9a-zA-Z`]+$"
}

The problem here is in ` (U0060) character. The code generator builds the validation helper as:

"{{ .NameSpace }}Pattern = regexp.MustCompile(`" + pattern + "`)"

and contains incorrect escaped Go string if pattern contains U0060 character inside.
Need to properly escape regexp pattern!

@Pilatuz
Copy link
Author

Pilatuz commented Oct 11, 2021

also need to escape %, otherwise error message became incorrect because it embeds pattern in format string.

If regexp pattern is 0-9%v then we will have:

message:  fmt.Sprintf(`must match '0-9%v' but got %q`, *m.Name),

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

1 participant