8000 [Translation] Allow to escape pipe by wouterj · Pull Request #15206 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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
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

0