-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translation][transChoice] allows escaping the pipe character. #17662
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
Conversation
Q | A |
---|---|
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | no |
Fixed tickets | #15195 |
Tests pass? | yes |
License | MIT |
@@ -47,11 +47,11 @@ class MessageSelector | |||
*/ | |||
public function choose($message, $number, $locale) | |||
{ | |||
$parts = explode('|', $message); | |||
$parts = preg_split('/(?<![^\\\\]\\\\)\|/', $message); |
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.
It doesn't work as expected with "a\\\\\|b
" (escaped backslash, escaped backslash, escaped "|"). I don't think it's possible to solve it properly with a single regex.
@aitboudad Any news on this one? |
technically, this is a BC break if someone has a Btw, a simpler solution (avoiding the issue about having to escape |
I agree with @stof. Doubling the pipe to escape it seems the way to go. @aitboudad What do you think? |
94fd3b7
to
7974ebd
Compare
sounds good to me, I updated the PR! |
@@ -47,11 +47,11 @@ class MessageSelector | |||
*/ | |||
public function choose($message, $number, $locale) | |||
{ | |||
$parts = explode('|', $message); | |||
preg_match_all('/(?:\|\|.|[^\|])+/', $message, $parts); |
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.
why .
after the double pipe ? this would also match a pipe.
Btw, you should use a possessive quantifier to avoid useless backtracking
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.
done
7974ebd
to
a35a93b
Compare
Thank you @aitboudad. |
…aracter. (aitboudad) This PR was merged into the 3.2-dev branch. Discussion ---------- [Translation][transChoice] allows escaping the pipe character. | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Fixed tickets | #15195 | Tests pass? | yes | License | MIT Commits ------- a35a93b [Translation][transChoice] allows escaping the pipe character.