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

Ability to customize regular expression engine #192

Merged
merged 1 commit into from
May 16, 2024

Conversation

sandwoodK
Copy link
Contributor

class Validator becomes a templated type accepting a RegexEngine type which perform the regular expression creation and matching for the pattern constraint.

Provide the DefaultRegexEngine which perform exactly as of today (using std::regex). No breaking changes in library user.

(note that other place where std::regex are in used are not changed, (.i.e format constraint) because they are not likely to cause issue (regular expression is hard coded, not coming from the schema).

Add 2 examples with gtest_skip that can easily be uncommented to exercice the 2 problems.

Not added, because I don't want to add new dependency in the project : a full example of what can be a CustomRegexEngine class handling both problem. This can be done with pcre which allows to set
match_limit and match_limit_recursion on a pcre_extra struct that can be passed to the pcre_exec.
In case theses limits are reached obviously we are not able to really know if the payload match the pattern but we can safely handle this without crash or infinite recursion.

This solution also gives library user the ability to choose any Regular Expression engine depending on its use case.

@tristanpenman
Copy link
Owner

Hi @sandwoodK, thank you very much for taking the time to do this. I'm currently on vacation, so I am unable to review the changeset properly. However, what I've seen so far looks very good! 👏👏

I'll let you know once I have had a chance to review it properly, so that we can get this merged.

@tristanpenman tristanpenman merged commit 31ce4a5 into tristanpenman:master May 16, 2024
3 checks passed
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

Successfully merging this pull request may close these issues.

2 participants