Make sure the regex validation is anchored#236
Merged
Bergmann89 merged 2 commits intoBergmann89:masterfrom Feb 13, 2026
Merged
Conversation
Bergmann89
requested changes
Feb 12, 2026
Owner
Bergmann89
left a comment
There was a problem hiding this comment.
Hey @p32blo,
Thanks for the fix, I really appreciate that 👍
Just one small remark: Could you please use the following code to resolve the str instead of simply hard coding it? Otherwise code generation might break for configurations that expect absolut paths for build-in types. Thanks 😊
let str_ = resolve_build_in!(ctx, "::core::primitive::str");
static PATTERNS: #lazy_lock<[(&#str_, #regex); #sz]> = #lazy_lock::new(|| [ #( #patterns )* ]);
Contributor
Author
|
Thanks for the quick turn around time, you're awesome !! |
Owner
|
You are welcome and thanks for your contribution 😊 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While experimenting with
xs:patternvalidation I noticed that some values were passing validation when they should fail.This PR makes sure the regex pattern match is anchored in accordance to the xsd standard, otherwise it would be possible to match only a part of the string, for example:
\dwould match not only1or2but also11,12and22.Besides adding the anchors (
^$), I also used an non-capturing group(?:)to make sure that when we have a pattern likedog|catwe don't consider it as^dogorcat$but as^(dog|cat)$. Being non-capturing means that it won't count for the normal group index calculation.XSD Standard
Here is the relevant section of the standard: https://www.w3.org/TR/xmlschema11-2/
Feel free to change, correct or otherwise comment on the PR
(or delete if doesn't make sense 😢 )