From 4c0cdb6a84522979394723f79a52c3a48651fbfa Mon Sep 17 00:00:00 2001 From: Sergiy Borodych Date: Wed, 9 Sep 2020 11:02:47 +0300 Subject: [PATCH 1/2] fix uri_base to return URI object always instead of stringified scalar that makes consistency better in cases of: - with the 'base' method, now both return URI objects - in various cases of '/' at end --- lib/Dancer2/Core/Request.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Dancer2/Core/Request.pm b/lib/Dancer2/Core/Request.pm index 980ed3d28..b80546230 100644 --- a/lib/Dancer2/Core/Request.pm +++ b/lib/Dancer2/Core/Request.pm @@ -287,8 +287,8 @@ sub uri_base { my $uri = $self->_common_uri; my $canon = $uri->canonical; - if ( $uri->path eq '/' ) { - $canon =~ s{/$}{}; + if ( $canon->path eq '/' ) { + $canon->path(''); } return $canon; From c8ea04628203c10e3518b4ffd0adb1c64959de25 Mon Sep 17 00:00:00 2001 From: Sergiy Borodych Date: Wed, 9 Sep 2020 11:20:25 +0300 Subject: [PATCH 2/2] apply canonical in _common_uri since it is in common usage --- lib/Dancer2/Core/Request.pm | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/Dancer2/Core/Request.pm b/lib/Dancer2/Core/Request.pm index b80546230..0d9a7a8c8 100644 --- a/lib/Dancer2/Core/Request.pm +++ b/lib/Dancer2/Core/Request.pm @@ -258,13 +258,6 @@ sub to_string { return "[#" . $self->id . "] " . $self->method . " " . $self->path; } -sub base { - my $self = shift; - my $uri = $self->_common_uri; - - return $uri->canonical; -} - sub _common_uri { my $self = shift; @@ -279,19 +272,20 @@ sub _common_uri { $uri->authority( $host || "$server:$port" ); $uri->path( $path || '/' ); - return $uri; + return $uri->canonical; } +sub base { return $_[0]->_common_uri; } + sub uri_base { - my $self = shift; - my $uri = $self->_common_uri; - my $canon = $uri->canonical; + my $self = shift; + my $uri = $self->_common_uri; - if ( $canon->path eq '/' ) { - $canon->path(''); + if ( $uri->path eq '/' ) { + $uri->path(''); } - return $canon; + return $uri; } sub dispatch_path {