Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Translation] Allow to escape pipe #15206

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

Closed
wants to merge 1 commit into from
Closed

Conversation

wouterj
Copy link
Member

@wouterj wouterj commented Jul 5, 2015

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

This allows for escaping the pipe character, so pipes can be used in strings passed to transchoice.

@wouterj wouterj changed the title Allow to escape pipe [Translation] Allow to escape pipe Jul 5, 2015
@@ -51,7 +51,7 @@ 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.

But it doesn't allow to escape backslash itself.

Choose a reason for hiding this comment

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

This should be enough for any case:

$parts = array_map(function($value){
    return str_replace('\|','|',str_replace('\\\\','\\',$value));
},preg_split( '/(?<![^\\\\]\\\\)\|/', $message));

It ignores escaped pipes, ignore escaped backslashes and after split it replaces escaped pipes to pipes and escaped backslashes to backslash.

there needs to be 4 backslashes to escape to one before a pipe though, but hey, it's a way.

Copy link
Contributor

Choose a reason for hiding this comment

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

@emiliopedrollo I used your proposal see #17662

@linaori
Copy link
Contributor

linaori commented Jul 6, 2015

Wouldn't this cause a performance impact for 99% of the users while only 1% uses this weird case?

@keradus
Copy link
Member

keradus commented Jul 6, 2015

You should add new test for that

@wouterj
Copy link
Member Author

wouterj commented Jul 21, 2015

Closing as the fix wasn't as easy as I thought and I'm not the qualified regex dev to do it :)

@wouterj wouterj closed this Jul 21, 2015
@wouterj wouterj deleted the patch-10 branch July 21, 2015 11:54
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.

6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.