delete
delete

Reputation: 19148

Symfony2 Routing Requirements: how to enable UTF-8 mode?

I want to use the following regex as an requirement for symfony2 routing:

/^[ \x{00C0}-\x{01FF}a-zA-Z'\-]+$/u

The special thing here is to enable the utf8-mode with the u-modifier at the end. How to pass this /u to requirement-section of a symfony routing.yml?

Our current routing.yml looks like that:

search_by_name:
    path:     /search/name/{name}-4/{page}/{limit}
    defaults: { _controller: SearchBundle:SearchByName:index, page: 0, limit: 8 }
    requirements:
        name: "[äüößÄÖÜ´\"`èéa-zA-Z\-]+"

Now we want to apply the pattern mentioned above:

    requirements:
        name: "[ \x{00C0}-\x{01FF}a-zA-Z'\-]+"  <-- "u" is missing

Where to pass the "u"? Just adding the character at the end will result in the following error:

Warning: preg_match(): Compilation failed: character value in \x{...} sequence is too large at offset 61

Upvotes: 2

Views: 1026

Answers (1)

K&#233;vin Dunglas
K&#233;vin Dunglas

Reputation: 3024

The Symfony Routing component doesn't support fully Unicode ; basically because it doesn't use multibyte-safe string functions internally. Unexpected issues can occurs when using such flags.

Progress in Unicode support in the component is tracked in the following issue: https://github.com/symfony/symfony/issues/5236

Upvotes: 1

Related Questions