-
Notifications
You must be signed in to change notification settings - Fork 41
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
fix(payload-schemas): add custom RegEx validation for 'email' #677
Conversation
@timrogers @wolfy1339 before fixing the Regex I references in a code comment, I wanted to validate with you this solution proposal. What do you think? |
You don't need to specify it that way, you can simply pass in a regex for validation directly in the schema itself using the https://json-schema.org/understanding-json-schema/reference/string.html#pattern |
It's because the emails aren't compliant with the RFC, not because of anything related to the JSON schema itself. RFC 5322 Section 3.4 defines valid email addresses I just want that to be obvious, so we are all on the same page and don't blame the wrong people. Also, don't forget to re-generate the |
I agree on this. Personally, I think we should just remove From the JSON Schema standard's perspective, it is a string as it doesn't conform to the email RFC. |
Here's a modified version of AJV's regex for email validation that works with the emails we have ^[a-z0-9!#$%&'*+/=?^_`{|}~\-\[\]]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~\-\[\]]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$ |
Could you guide me on which part of the code are we supposed to add this
@timrogers wolfy already got a regex to cover our use-case, I would prefer to use that so we don't allow non-valid e-mails and add extend the regex to cover our use-case. Any downsides of using it? |
Instead of having |
The downside, in my opinion, is that people might be using these schemas in another language with another JSON Schema validation tool. If someone uses another tool, it won't know that we have "redefined" |
Totally agree. Which is why I suggested the |
Ah, makes sense - I missed "in the schema" in your comment above. I think that would be the best way of doing it: don't use the |
67a26a0
to
401c14c
Compare
I had to double escape some characters (due to JSON but the RegExp is not matching after escaping). Any clue on what I'm doing wrong @wolfy1339 ? Should we migrate the rest of schemas with |
401c14c
to
561fb88
Compare
The double escapes are changing the meaning of the RegExp. The backslashes are escapes themselves for characters in the RegExp, and by escaping them, you're changing their meaning to be a backslash. That's all I can think of |
Honestly I don't think we should be messing with a pattern regexp like that, as it's a good way to cause more trouble (the size of it alone is huge even before you think about all the subpatterns). If that field is meant to hold valid emails then they should be valid according to the spec; otherwise they are a string and should not be validated further than that. The third option I'd be happy with is matching whatever validation that |
This is the issue I'm getting, invalid JSON basically:
I can agree the RegEx is very long and hard to follow but basically, we are extending the one we were already using with Your point of not following a standard is interesting but at least there are some basic patterns of an email address we should be covering, right? |
My point is we should be matching whatever is using that field because that's what actually matters or otherwise should not be validating it at all - anything else means that we are being incorrect. Sometimes that is fine because the fix can be straightforward, but in this case it's a honking big RegExp that we've sourced from somewhere else i.e. consider if someone else comes along and presents another email that is considered invalid by this pattern but works with (also consider the time you've already spent on trying to get this working) |
If we are to remove it, we should also document it somewhere |
Created associated PR here already in case we end up deciding on this solution: #678 I am still checking why this Regex is not working as a personal challenge 🤓 and pushing the working solution. |
561fb88
to
623d3bc
Compare
623d3bc
to
3cb527b
Compare
Found the issue, we were missing the |
For reasons listed above, i think it's best to leave this issue alone. As GitHub has published it's own OpenAPI spec for webhooks, efforts will be concentrated on the current community spec and transitioning to the official spec |
Description
emails
inajv
index.json
Context
Current JSON Schema validation foremails
does not support emails with this format.EDIT:
Example of not supported format:
41898282+github-actions
[bot
]@users.noreply.github.com
Fixes #453