Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Symfony 4 only supports routes with UTF-8 characters if they have the utf8 option set to TRUE.
Proposed resolution
Set the utf8 option in our RouteCompiler class and ensure routes are using this compiler class.
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#29 | 2961688-2-29.patch | 9.45 KB | alexpott |
#29 | 26-29-interdiff.txt | 2.92 KB | alexpott |
#26 | 2961688-2-26.patch | 7.75 KB | alexpott |
#26 | 22-26-interdiff.txt | 795 bytes | alexpott |
#22 | 2961688-2-22.patch | 7.7 KB | alexpott |
Comments
Comment #2
alexpottComment #3
BerdirWell, nothing prevents you from entering a path like that in views or page manager for example?
Makes me wonder if that is even really relevant for us, I assume this might be related to how their default router lookup now works, for our database-based lookup, does it really matter?
Comment #4
alexpottUpdated issue summary with #3. I thought of views when I was thinking but I got distracted by the fact views can't have utf8 in their IDs but that is totally irrelevant.
Comment #5
martin107 CreditAttribution: martin107 as a volunteer commentedThis is coming into sharp relief...
When Investigatory patches bump the symfony version all the way up to eleven .... er I mean 4
Then testbot starts spitting out all the errors which show that this patch is much needed.
see
#2976394: Allow Symfony 4.4 to be installed in Drupal 8
Over there in relation to the comment in #11B
https://www.drupal.org/project/drupal/issues/2976394#comment-12636129
From what I see the current patch is a natural solution to the errors listed in the corresponding test run [ see below ].
https://www.drupal.org/pift-ci-job/978873
In response to #3 above ... I think we are going to have to find a general solution to views/page managers etc.
This patch is far from complete...
As usual I will help out where I can.
TLDR;
I stupidly created a duplicate issue ... before I could shut that down Catch moved that issue to major.
#2976649: Make auto handling of utf8 routes deprecated I agree and so I am upgrading this issue.
Comment #6
martin107 CreditAttribution: martin107 as a volunteer commentedLooking at views question, here is an example which applies broadly. and just echoes #4.
entity.view.edit_form:
path: '/admin/structure/views/view/{view}'
the variable {view} is derived from the machine name .. so limited to lowercase[a-z] and underscore.
@Bedir
Can you expand on the page manager comment in #3?
Or just point me at an example of what is on your mind.
I am still trying to decide if we are sitting on a upgrade headache... or not.
Comment #7
martin107 CreditAttribution: martin107 as a volunteer commentedReroll.
Comment #9
martin107 CreditAttribution: martin107 as a volunteer commentedreroll.
Comment #10
Mile23LGTM. I tried reverting the
RoutingFixtures
files and ran a few tests that ended up failing on deprecation errors. Then I revertedsystem_test.routing.yml
to the same result.Comment #12
longwaveThis patch doesn't take this into account. If I remove the @ from the trigger_error() line in RouteCompiler::compilePattern() and then create a Views page with a custom path that uses UTF-8 characters, the deprecation warning is logged in watchdog. Looks like this might need to be detected and handled in our RouteBuilder class?
Comment #13
tstoecklerRe #12 wouldn't it be sufficient for
\Drupal\views\Plugin\views\display\PathPluginBase::getRoute()
to conditionally specify theutf-8
option as part of the generated route?Comment #14
longwaveI guess the question is, do we need to fix this for Views only, or are there enough places that users can enter custom paths elsewhere that we need to provide a more generic solution? I didn't test custom URL aliases for nodes, for example.
Comment #15
BerdirThanks for pointing out views, I wanted to do that as well but didn't get to it yet ;)
Aliases aren't routes, they are resolved before that.
AFAIK views is currently the only place in core where users can define the actual routes. But there's also Page manager and possibly more things like that in Contrib.
Comment #16
alexpott@longwave++ was just about to write something along the same lines.
Here's a patch that sets the UTF-8 option for all routes.
Comment #17
alexpottAlso we don't support non-UTF8 routes.
I tried adding
to
\Drupal\Tests\Core\Routing\RoutingFixtures::complexRouteCollection()
and gotDrupal\Core\Database\DatabaseExceptionWrapper : SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xE9' for column 'path'
So maybe we could just always set the UTF-8 option and not do
if (preg_match('//u', $route->getPath())) {
Comment #18
alexpottAlso it is not just views... a module could have
In it's routing.yml file.
Comment #20
alexpottFunky so routes generated by the rebuild don't have the correct compiler class.
Comment #22
alexpottSo let's use
RouteCompiler::class
everywhere so it is standardised. Also need to fix the test.Comment #23
alexpottSo as far as I can see the last to resolve here is whether or not the if has any point because I can't see how we support non-utf8 routes. See #17
Comment #24
longwaveI don't see how we can support non-UTF8 routes either. MatcherDumper always wants to write the entire route collection to the database, no exceptions, and if the database only supports UTF8 then logically the route path can only be UTF8 as well.
I guess there are extreme edge cases where someone either changes the database character set or replaces the route dumper service with some other backend - but I don't think we should consider supporting this as they could always override the route compiler class as well if they need to.
NW to always set the UTF8 option.
Comment #25
BerdirIf I understand this correctly, then this is about https://symfony.com/blog/new-in-symfony-3-2-unicode-routing-support. So before Symfony 3.2, *they* didn't support utf8 at all.
But that's never been true for us anyway with our database-based matcher, we always supported it and as pointed out, we in fact can not "not support" it. The whole thing seems a bit unfortunate in how it's implemented, because we call that compilePattern() method in some but very few cases (building the routes calls it from \Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber::alterRoutes()*, and at runtime \Drupal\Core\Routing\UrlGenerator::getInternalPathFromRoute() calls compile(), the only call to that that I see in my default installation is from bigpipe.
And then it only uses that flag to set the u modifier on route regexp, which we AFAIK never use anyway. I guess most of what compilePatterns() does is not relevant for us? So we just need to get rid of the deprecation messages and always setting it is fine.
* Pretty sure several things that are being checked in there haven't existed in a very long time, e..g _content.
Comment #26
alexpottPatches addresses #23. Thanks for the reviews @Berdir and @longwave.
Comment #27
longwave#26 looks good.
Comment #28
larowlanshould we do this only if a value doesn't exist? i.e.
what if a contrib/client project wants to use their own snowflake compiler?
Comment #29
alexpott@larowlan that's not possible. Err... no I'm wrong. Here's a test for doing just that. Nice catch!
Hopefully there are not too many snowflake compilers out there though.
Comment #30
larowlan+1 thanks
Comment #31
jibranDo we need/link a change notice?
Comment #32
alexpott@jibran nothing is changing. We already do not support non-UTF8 routes - see comments above.
Comment #33
jibranok
Comment #34
larowlanAdding review credits
Comment #35
larowlanCommitted 729b440 and pushed to 8.7.x. Thanks!
Comment #37
Mile23