Search code examples
perlroutesmojolicious

Mojolicious route with a parameter not matching if the parameter contains %2f


I have the following route

  $r->get('/select_folder/:mail')->to('mail#change_folder');

It works well almost every time but when the route contains the %2f sequence of characters, equivalent to / it works as if %2f is a path separatator instead of a escaped sequence.

This is an example input:

http://127.0.0.1:5000/select_folder/%5bGmail%5d%2fDestacados

This is part of the error:

None of these routes could generate a response for your GET request for /select_folder/[Gmail]/Destacados, maybe you need to add a new one?

I would like to know some way to get a parameter like this as an url part without using GET or POST parameters.


Solution

  • You can use wildcard placeholders to allow / to be part of the matched parameter.

      $r->get('/select_folder/*mail')->to('mail#change_folder');
    

    The reason why %2F is interpreted as a / is because the URL is decoded before being applied to routing.