Underline as segment_separators in routing.yml

In a symfony project, I would like to use underscore as a separator for a parameter in routing.yml.

Example URL: / article / lorem -1111_45.html

In routing.yml

rule_sample: url: /article/:info-:datePublished_:id.html param: { module: cms, action: test } options: segment_separators: ['-', '/', '.', '_'] requirements: info: ^([A-Za-z0-9\-]+)$ datePublished: \d+ id: \d+ 

This code does not work. I have the following error: Failed to parse route "/article/:info-:datePublished_:id.html". ": Id.html"

Does anyone know how to implement this rule?

+4
source share
2 answers

I think this is a bug in sfRoute.class.php. Line 683: 'variable_regex' => '[\ w \ d_] +'

in PHP \ w "Matches any alphanumeric character, including the underscore (_)", and the last underscore matches it. I tried changing this line to: 'variable_regex' => '[\ A-Za-z \ d] +'

And now I can use the underline as a separator.

I have not experienced this very much. I don't know if this caused any other functions (of course), but maybe this is the line where Symfony programmers can run this error.

+1
source

I believe this is a bug in symfony.

I made a test that failed and sent with a test to the symfony project

0
source

Source: https://habr.com/ru/post/1310717/


All Articles