Symfony 2.1+ encodes hash / pound "#" in routes

I am upgrading from Symfony 2.0 to 2.3. We have routes with hashes defined as we have a single page application.

Annotation configured route:

/** * @Route("/app#orders/{id}", name="app_order") */ 

We use Twig to create email and use these routes in Twig templates:

 <a href="{{ url('app_order', { 'id': '123' }) }}">View order</a> 

Before the upgrade, everything went fine. After the upgrade, # gets the encoding to %23 , but the slashes remain untouched. This, of course, generates an invalid URL in the email.

Why only hash encoding and not slashes? It should be all or nothing. What options do I have here besides replacing the string?

Things I've already tried doing that don't help:

  • Setting autoescape to false {% autoescape false %}
  • Using raw {{ url(...)|raw }}
  • Using raw and autoescape = false together
+4
source share
1 answer

If you look at UrlGenerator , you can see that the hashtag is not decoded after rawurlencode . Hashtag highlighting has been added to commit 6039569 .

As a workaround, you can extend the UrlGenerator class and replace the $decodedChars array $decodedChars included hashtag. Then tell Symfony to use its generator class:

 parameters: router.options.generator_base_class: Acme\MyBundle\Routing\HashtagDecodedUrlGenerator 
+4
source

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


All Articles