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

Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Allow to escape pipe
  • Loading branch information
wouterj committed Jul 5, 2015
commit 403d9c0495603fef3c7d45162aec68e1591caf3e
2 changes: 1 addition & 1 deletion src/Symfony/Component/Translation/MessageSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

$explicitRules = array();
$standardRules = array();
foreach ($parts as $part) {
Expand Down
0