Skip to content

[HttpFoundation] use brace-style regex delimiters #27152

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

Merged
merged 1 commit into from
May 6, 2018

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented May 4, 2018

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #27107
License MIT
Doc PR

@stof
Copy link
Member

stof commented May 4, 2018

Simpler solution: use {} as delimiters. These have a special meaning inside the regex already, so don't require extra quoting just because of being the delimiter. This is the strategy used in Composer.

@@ -581,7 +581,7 @@ public static function getTrustedProxies()
public static function setTrustedHosts(array $hostPatterns)
{
self::$trustedHostPatterns = array_map(function ($hostPattern) {
return sprintf('#%s#i', $hostPattern);
return sprintf('#%s#i', preg_replace('/(?<!\\\\)#/', '\\#', $hostPattern));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets' use {} as @stof suggested

@xabbuh xabbuh changed the title [HttpFoundation] escape the regex delimiter character [HttpFoundation] use brace-style regex delimiters May 6, 2018
@xabbuh
Copy link
Member Author

xabbuh commented May 6, 2018

Status: Needs Review

@xabbuh
Copy link
Member Author

xabbuh commented May 6, 2018

I have switched to using curly braces as suggested by @stof.

@fabpot
Copy link
Member

fabpot commented May 6, 2018

Thank you @xabbuh.

@fabpot fabpot merged commit ae62d9b into symfony:2.7 May 6, 2018
fabpot added a commit that referenced this pull request May 6, 2018
This PR was merged into the 2.7 branch.

Discussion
----------

[HttpFoundation] use brace-style regex delimiters

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27107
| License       | MIT
| Doc PR        |

Commits
-------

ae62d9b use brace-style regex delimiters
@xabbuh xabbuh deleted the issue-27107 branch May 6, 2018 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants