10000 [Translation][transChoice] allows escaping the pipe character. by aitboudad · Pull Request #17662 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[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

Merged
merged 1 commit into from
Jun 14, 2016

Conversation

aitboudad
Copy link
Contributor
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);
Copy link
Contributor

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.

@fabpot
Copy link
Member
fabpot commented Mar 2, 2016

@aitboudad Any news on this one?

@stof
Copy link
Member
stof commented Apr 8, 2016

technically, this is a BC break if someone has a \ at the end of a part.

Btw, a simpler solution (avoiding the issue about having to escape \ itself) would be to escape the pipe by doubling it (similar to the escaping of single quotes in YAML, or in SQL strings on Postgresql).
And this would even be almost BC. People cannot have a part ending with a pipe character today anyway. the only reason to have a double pipe would be to have one of the pluralization alterna 10000 tives being an empty string, but this looks really weird.

@fabpot
Copy link
Member
fabpot commented Jun 14, 2016

I agree with @stof. Doubling the pipe to escape it seems the way to go. @aitboudad What do you think?

@aitboudad aitboudad force-pushed the translation_escape_pipe branch 2 times, most recently from 94fd3b7 to 7974ebd Compare June 14, 2016 14:27
@aitboudad
Copy link
Contributor Author

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);
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@aitboudad aitboudad force-pushed the translation_escape_pipe branch from 7974ebd to a35a93b Compare June 14, 2016 15:15
@fabpot
Copy link
Member
fabpot commented Jun 14, 2016

Thank you @aitboudad.

@fabpot fabpot merged commit a35a93b into symfony:master Jun 14, 2016
fabpot added a commit that referenced this pull request Jun 14, 2016
…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.
@aitboudad aitboudad deleted the translation_escape_pipe branch June 15, 2016 10:37
@fabpot fabpot mentioned this pull request Oct 27, 2016
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.

7 participants
0