Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Small but essential fix for AllowEncodedSlashes - fixes also PATH_INFO.
  • Loading branch information
Markus Jansen committed Sep 3, 2014
commit 1f61bbe90c770513eb4293255fc558fae303e737
14 changes: 12 additions & 2 deletions lib/Dancer/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,17 @@ sub _build_path {

if ($path eq '' && defined $request_uri) {
# $request_uri =~ s/\?.*$//;
$path = $self->_url_decode($request_uri, !$unencode_slashes);
my ( $request_uri_path, $query_string ) =
$request_uri =~ /^([^?]+)(\?.*)$/ ? ( $1, $2 ) : ( $request_uri, '' );
$path = $self->_url_decode($request_uri_path, !$unencode_slashes);

# change PATH_INFO in retrospect if we can safely do so
my $path_info = $self->env->{PATH_INFO} || '';
my $unencoded_request_uri_path = $self->_url_decode($request_uri_path);
if ( $unencoded_request_uri_path ne $path &&
$unencoded_request_uri_path eq $path_info ) {
$self->env->{PATH_INFO} = $path;
}
}

raise core_request => "Cannot resolve path" if not $path;
Expand Down Expand Up @@ -500,7 +510,7 @@ sub _url_decode {
$clean =~ tr/\+/ /;
if ($allow_encoded_slashes) {
# don't pack %2F
$clean =~ s/%([a-fA-F013-9][a-fA-F0-9]|2[a-eA-e0-9])/pack "H2", $1/eg;
$clean =~ s/%([a-fA-F013-9][a-fA-F0-9]|2[a-eA-E0-9])/pack "H2", $1/eg;
}
else {
$clean =~ s/%([a-fA-F0-9]{2})/pack "H2", $1/eg;
Expand Down