Iliya Reyzis
Iliya Reyzis

Reputation: 3687

mojolicious disable dot placeholder routing

Background

I have this routing

my $foo = $r->get('/foo/:asd')->to('Foo#bar');

in the controller I'm just rendering some json with the passed param (with the help of Mojolicious::Controller::REST)

$self->data( 'param' => $self->param('asd') );


The Problem

When sending a request to /foo/bar, its working as expected:

{"data":{"param":"bar"}}

but when I'm trying to pass a string that is containing a dot, an email for example ([email protected]), mojo is rendering the dot as a slash. The routing I defined in the first place is not longer relevant, because now the pattern has changed to foo/:bar/:baz


The Solution

I was told that the solution is around here: https://github.com/kraih/mojo/blob/master/t/mojolicious/routes.t#L218
It make sense, but I do not understand how to combine that with what I have.

I tried to add $foo->pattern->placeholder_start('+'); to my routing, but still, the pattern is changing and its irrelevant all over again. It doesn't look like its going to disable the dot related to my problem.

I tried implement the pattern method on the $r variable (which is the Mojo's routing - $self->routes)

Bottom line, I just need to disable the dot placeholder for certain routing or entirely.

Thanks

Upvotes: 3

Views: 586

Answers (1)

mob
mob

Reputation: 118695

Mojolicious supports three kinds of placeholder parameters:

Standard

my $foo = $r->get('/foo/:asd')->to('Foo#bar');

Relaxed

my $foo = $r->get('/foo/#asd')->to('Foo#bar');

Wildcards

my $foo = $r->get('/foo/*asd')->to('Foo#bar');

Standard placeholders can match all characters except . and / . Relaxed placeholders can match all characters except /. Wildcard placeholders can match all characters. So if you want to support parameter values with . or /, you must use the relaxed or wildcard style placeholders.

Upvotes: 8

Related Questions