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

Issue parsing regex => improve docs and error message #32

Closed
lukasmalkmus opened this issue Jan 17, 2018 · 2 comments · Fixed by #36
Closed

Issue parsing regex => improve docs and error message #32

lukasmalkmus opened this issue Jan 17, 2018 · 2 comments · Fixed by #36

Comments

@lukasmalkmus
Copy link
Contributor

lukasmalkmus commented Jan 17, 2018

I wanted to use go-proto-validators to validate the field of a message by using regular expressions. This is the regular expression I used: [\p{L}\p{N}]({\p{L}\p{N}_- ]{0,28}[\p{L}\p{N}])?.

And... It didn't work as expected. Why? The regex isn't valid, because you can't use \ in a string ". Take a look at the generated code:

regexp.MustCompile("[\p{L}\p{N}]({\p{L}\p{N}_- ]{0,28}[\p{L}\p{N}])?.") # Does panic!

You need to escape the backtick with another one: [\\p{L}\\p{N}]({\\p{L}\\p{N}_- ]{0,28}[\\p{L}\\p{N}])?.. This works, but also produces and ugly error message.

I can't decide if this should be treated like an error or not. But we should at least put a note in the README.

@mwitkow
Copy link
Owner

mwitkow commented Apr 1, 2018

Ok, this sounds like whatever we're parsing from protobuf field options should be escaped into the MustCompile string, or the MustCompile codegen should be using """. Fancy taking a stab at fixing this?

@lukasmalkmus
Copy link
Contributor Author

lukasmalkmus commented Apr 1, 2018

@mwitkow Take a look at #36. I would love some feedback and additional testing.

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

Successfully merging a pull request may close this issue.

2 participants