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

Passing certain characters to add_chars() method causes "preg_match_all(): Unknown modifier ']'" #55

Closed
cbj4074 opened this issue Feb 4, 2019 · 1 comment

Comments

@cbj4074
Copy link
Contributor

cbj4074 commented Feb 4, 2019

Consider the following:

URLify::add_chars(['/' => '']);

This causes a language exception, preg_match_all(): Unknown modifier ']', because the / character is used as the regular expression delimiter within the URLify library.

The above example derives from a fairly common and reasonable use-case: I want to remove all illegal characters from a file name, and on UNIX and Windows, / is illegal.

To fix this, PHP's preg_quote() function must be called on the keys in the array argument passed to add_chars().

I'll submit a PR shortly that seeks to fix the issue.

cbj4074 added a commit to cbj4074/urlify that referenced this issue Feb 4, 2019
This change fixes a language exception that occurs when a character
that is used as a regular expression delimiter ("/" by default) is
included as a key in the array argument passed into the add_chars()
method, and the downcode() is called.

Note that the existing tests do not cover this scenario.
cbj4074 added a commit to cbj4074/urlify that referenced this issue Feb 4, 2019
This change fixes a language exception that occurs when a character
that is used as a regular expression delimiter ("/" by default) is
included as a key in the array argument passed into the add_chars()
method, and then downcode() is called.

Note that the existing tests do not cover this scenario.
lux added a commit that referenced this issue Jun 5, 2019
@lux
Copy link
Collaborator

lux commented Jun 5, 2019

Fixed in #56

@lux lux closed this as completed Jun 5, 2019
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

No branches or pull requests

2 participants