-
Notifications
You must be signed in to change notification settings - Fork 353
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 #133 regex dot in character class #135
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I tested with random seed and complex regex
dataset and it works perfectly!
test/Faker/Provider/BaseTest.php
Outdated
@@ -337,6 +337,7 @@ public function regexifyDataProvider() | |||
['[a-z]{2,3}', 'brackets quantifiers on character class range'], | |||
['(a|b){2,3}', 'brackets quantifiers on alternation'], | |||
['\.\*\?\+', 'escaped characters'], | |||
['[.]', 'literal dot'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's worth to add a test asserting that calling regexify('[.]')
will always return "."
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good idea, added it to the already existing test cases here:
https://github.com/FakerPHP/Faker/pull/135/files#diff-c648f7b997049e16add4fc6034d0c6f41f5c6b0c6a52a14b7fe4dd797a2a873cR313
But a literal dot in regex always need an escape in the input? With this change we actually limit ourself in normal regex use with a catchall dot itself? |
Signed-off-by: Daniel Schmelz <daniel@schmelz.org>
In a bracketed character class a dot does not have to be escaped to be interpreted as a literal dot: https://perldoc.perl.org/perlrecharclass#Bracketed-Character-Classes The problem here was, that the character class replacement logic did not take that into account. When called with Faker/src/Faker/Provider/Base.php Lines 496 to 499 in afa2aab
which is then erroneously replaced with a random ascii character here Faker/src/Faker/Provider/Base.php Line 503 in afa2aab
When the character class character selector returns Faker/src/Faker/Provider/Base.php Line 505 in afa2aab
with the expected end result of a literal dot. To verify that calling Btw thinking about this I realized that we probably have other related issues here, for example when regexify is called with |
@krsriq shall we merge this one and raise a new issue for the other issue? This way we already close this bug right away |
@pimjansen - yes, good idea! |
Thanks! |
What is the reason for this PR?
regexify
produces a random character instead of a literal dot when called within a character class (e.g.[.]
).Author's checklist
Summary of changes
Fixes the issue, adds test to verify.
Review checklist