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

Fix regex dot/backslash issue #206

Merged
merged 6 commits into from
Dec 21, 2020
Merged

Conversation

krsriq
Copy link

@krsriq krsriq commented Dec 21, 2020

What is the reason for this PR?

There are two bugs in regexify that make #134 fail: when regexify is called with a dot (matches any character in regex), the dot may get replaced (by asciify) with a backslash, which is an escape character:

$regex = preg_replace_callback('/(?<!\\\)\./', 'static::randomAscii', $regex);

Secondly, all backslashes are removed - even the ones that are escaped:

$regex = str_replace('\\', '', $regex);

  • Fixed an issue
  • Covered by tests

Author's checklist

Summary of changes

This PR fixes the issues by checking whether asciify returns a backsash. In case it does it adds another backslash as escape character.
Additionally escaped backslashes are not removed by regexify any more.

Review checklist

  • All checks have passed
  • Changes are approved by maintainer

@krsriq krsriq mentioned this pull request Dec 21, 2020
4 tasks
@pimjansen pimjansen added the bug Something isn't working label Dec 21, 2020
@pimjansen
Copy link

Needs rebase

# Conflicts:
#	test/Faker/Provider/BaseTest.php
@krsriq
Copy link
Author

krsriq commented Dec 21, 2020

@pimjansen - done!

@pimjansen
Copy link

Phpcs is not green yet

@krsriq
Copy link
Author

krsriq commented Dec 21, 2020

Too quick with these style changes 😁

@pimjansen pimjansen merged commit 3328cb9 into FakerPHP:main Dec 21, 2020
@krsriq krsriq deleted the fix_regexify_backslash branch December 21, 2020 19:48
krsriq added a commit to krsriq/Faker that referenced this pull request Jan 7, 2021
* fix regex backslash

* fix regex backslash

* fix regex backslash

* run make cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants