From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 422B41F46D for ; Wed, 1 Jan 2020 10:39:00 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/6] www: move more logic into path_info_raw Date: Wed, 1 Jan 2020 10:38:55 +0000 Message-Id: <20200101103859.15401-3-e@80x24.org> In-Reply-To: <20200101103859.15401-1-e@80x24.org> References: <20200101103859.15401-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: It'll be easier to reuse in future code. --- lib/PublicInbox/WWW.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index 251979d5..13b66ee6 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -42,15 +42,17 @@ sub run { PublicInbox::WWW->new->call($req->env); } +# PATH_INFO is decoded, and we want the undecoded original my %path_re_cache; - -sub path_re ($) { - my $sn = $_[0]->{SCRIPT_NAME}; - $path_re_cache{$sn} ||= do { +sub path_info_raw ($) { + my ($env) = @_; + my $sn = $env->{SCRIPT_NAME}; + my $re = $path_re_cache{$sn} ||= do { $sn = '/'.$sn unless index($sn, '/') == 0; $sn =~ s!/\z!!; qr!\A(?:https?://[^/]+)?\Q$sn\E(/[^\?\#]+)!; }; + $env->{REQUEST_URI} =~ $re ? $1 : $env->{PATH_INFO}; } sub call { @@ -67,9 +69,7 @@ sub call { $k => $v; } split(/[&;]+/, $env->{QUERY_STRING}); - # avoiding $env->{PATH_INFO} here since that's already decoded - my ($path_info) = ($env->{REQUEST_URI} =~ path_re($env)); - $path_info //= $env->{PATH_INFO}; + my $path_info = path_info_raw($env); my $method = $env->{REQUEST_METHOD}; if ($method eq 'POST') {