Skip to content

Commit

Permalink
A set of fixes, thanks to Chris White (@cxw42)
Browse files Browse the repository at this point in the history
  • Loading branch information
xsawyerx committed Nov 14, 2023
1 parent 1211dbf commit 81c28ef
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
1 change: 0 additions & 1 deletion lib/Dancer2/Core/App.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use Safe::Isa;
use Sub::Quote;
use File::Spec;
use Module::Runtime qw< require_module use_module >;
use List::Util ();
use Ref::Util qw< is_ref is_arrayref is_globref is_scalarref is_regexpref >;

use Plack::App::File;
Expand Down
6 changes: 3 additions & 3 deletions lib/Dancer2/Core/DSL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package Dancer2::Core::DSL;
use Moo;
use Carp;
use Module::Runtime 'require_module';
use Ref::Util qw< is_arrayref >;
use Ref::Util qw< is_arrayref is_hashref >;
use Dancer2::Core::Hook;
use Dancer2::FileUtils;
use Dancer2::Core::Response::Delayed;
Expand Down Expand Up @@ -253,10 +253,10 @@ sub _normalize_route {
@args{qw<regexp options code>} = ( $_[0], {}, $_[1] );
} elsif ( @_ == 3 ) {
# @_ = ( REGEXP, OPTIONS, CODE )
# get '/foo', { 'user_agent' => '...', sub {...}
# get '/foo', { 'user_agent' => '...' }, sub {...}
# @_ = ( NAME, REGEXP, CODE )
# get 'foo', '/foo',sub {...}
if (ref $_[1] eq 'HASH') {
if ( is_hashref( $_[1] ) ) {
@args{qw<regexp options code>} = @_;
} else {
@args{qw<name regexp code>} = @_;
Expand Down
2 changes: 0 additions & 2 deletions lib/Dancer2/Core/Route.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use Type::Registry;

our ( $REQUEST, $RESPONSE, $RESPONDER, $WRITER, $ERROR_HANDLER );

my $count = 0;

has name => (
is => 'ro',
isa => Str,
Expand Down
2 changes: 1 addition & 1 deletion lib/Dancer2/Manual.pod
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ You can also provide routes with a name:

get 'hi_to' => '/hello/:name' => sub {...};

See C<uri_for_route> on how this can be used.
See L<Dancer2::Manual::Keywords/uri_for_route> on how this can be used.

=head3 Retrieving request parameters

Expand Down
26 changes: 21 additions & 5 deletions lib/Dancer2/Manual/Keywords.pod
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ URL encoding via a third parameter:

=head2 uri_for_route

An enhanced version of C<uri_for> that utilizes their names.
An enhanced version of C<uri_for> that utilizes routes' names.

get 'view_entry' => '/entry/view/:id' => sub {...};

Expand Down Expand Up @@ -1267,19 +1267,35 @@ second argument:
(Technically, only C<GET> requests should include query parameters, but
C<uri_for_route> does not enforce this.)

=item * Escaping
=item * Disable URI escaping

The final parameter determines whether the URI will be URI-escaped:
The final parameter determines whether the URI will be URI-escaped or not:

get 'show_entry' => '/view/:str_id' => sub {1};
# ...
$path = uri_for_route( 'show_entry' => { 'str_id' => '!£%^@' }, {}, 1 );
# $path = http://localhost/view/!@%C3%82%C2%A3$%
$path = uri_for_route(
'show_entry',
{ 'str_id' => '<javascript>...' },
{},
);
# $path = http://localhost/view/%3Cjavascript%3E...

This is useful when your ID is not HTML-safe and might include HTML
tags and Javascript code or include characters that interfere with the
URI request string (like a forward slash).

This is on by default, but you can disable it by setting this flag:

get 'show_entry' => '/view/:str_id' => sub {1};
# ...
$path = uri_for_route(
'show_entry',
{ 'str_id' => '<javascript>...' },
{},
1,
);
# $path = http://localhost/view/<javascript>...

=back

=head2 var
Expand Down

0 comments on commit 81c28ef

Please sign in to comment.