I need to generate links within an app based on data from an external data 
source. It contains data for a list of categories, and the category names 
may contain almost any character including slashes.

Given this minimal example app:

#!/usr/bin/env perl 
use Mojolicious::Lite; 
  
get '/:cat' => sub { 
  my $c = shift; 
  $c->render( 
          text =>  
             "stash cat:    " . $c->stash('cat') 
          . "\nurl_for:     " . $c->url_for('category', { cat => "foo / bar" 
}) 
          . "\nurl_for esc: " . $c->url_for('category', { cat => "foo %2F 
bar" }) 
          . "\n" 
  ); 
} => 'category'; 
  
app->start;

and invoking it like this,

carton exec -- perl app.pl get -v /foo

I see this result:

stash cat:   foo 
url_for:     /foo%20/%20bar 
url_for esc: /foo%20/%20bar

So "url_for" interpolates the data for the placeholder and uri-escapes the 
spaces but not the slash and also unescapes a pre-escaped slash.
I might get away with this using a wildcard placeholder (routes for the app 
are not completely decided upon, yet) or I might evade the problem by 
sending it as a query param.
But I´d still like to know if there is a way to force uri-escaping the 
slash or if that is intentionally not the case.
Other reserved (as in RFC 3986) chars apparently *are* uri-escaped (e.g. 
'#').
Maybe for slashes the placeholder type could be used to decide if a "/" has 
to be converted to "%2F" ("no" for wildcard placeholders, "yes" for 
standard and relaxed placeholders)?

Curious
- heiko

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to