From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C52BAC433E1 for ; Sun, 12 Jul 2020 18:57:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ADF05206F0 for ; Sun, 12 Jul 2020 18:57:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729306AbgGLS55 (ORCPT ); Sun, 12 Jul 2020 14:57:57 -0400 Received: from smtprelay01.ispgateway.de ([80.67.31.28]:50476 "EHLO smtprelay01.ispgateway.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729222AbgGLS55 (ORCPT ); Sun, 12 Jul 2020 14:57:57 -0400 Received: from [178.112.81.104] (helo=localhost.localdomain) by smtprelay01.ispgateway.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) (envelope-from ) id 1juhAf-0003n3-QZ; Sun, 12 Jul 2020 20:57:53 +0200 From: Tobias Girstmair To: git@vger.kernel.org Cc: Tobias Girstmair Subject: [PATCH v2] gitweb: Replace tag with full URLs (when using PATH_INFO) Date: Sun, 12 Jul 2020 20:24:19 +0200 Message-Id: <20200712182418.1696-1-tobi@isticktoit.net> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200711203947.23520-1-tobi@isticktoit.net> References: <20200711203947.23520-1-tobi@isticktoit.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Df-Sender: dC5naXJzdG1haXJAaXN0aWNrdG9pdC5uZXQ= Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org using a base tag has the side-effect of not just changing the few URLs of gitweb's static resources, but all other relative links (e.g. those in a README.html), too. Signed-off-by: Tobias Girstmair --- In v1 of this patch I didn't think about already absolute URLs. Fixed. tobias gitweb/gitweb.perl | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 0959a78..6a4f2fa 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -1616,6 +1616,19 @@ sub esc_url { return $str; } +# the stylesheet, favicon etc urls won't work correctly with path_info +# unless we set the appropriate base URL. not using a tag to not +# also change relative URLs inserted by the user. +sub esc_url_base { + my $url = shift; + my $prefix = $ENV{'PATH_INFO'}? esc_url($base_url)."/" : ""; + if (url !~ m{^(https?:)?//?}) { + return $prefix . esc_url($url); + } else { + return esc_url($url); + } +} + # quote unsafe characters in HTML attributes sub esc_attr { @@ -2232,7 +2245,7 @@ sub git_get_avatar { return $pre_white . "" . $post_white; } else { @@ -4099,17 +4112,17 @@ sub print_header_links { # print out each stylesheet that exist, providing backwards capability # for those people who defined $stylesheet in a config file if (defined $stylesheet) { - print ''."\n"; + print ''."\n"; } else { foreach my $stylesheet (@stylesheets) { next unless $stylesheet; - print ''."\n"; + print ''."\n"; } } print_feed_meta() if ($status eq '200 OK'); if (defined $favicon) { - print qq(\n); + print qq(\n); } } @@ -4212,11 +4225,6 @@ sub git_header_html { $title EOF - # the stylesheet, favicon etc urls won't work correctly with path_info - # unless we set the appropriate base URL - if ($ENV{'PATH_INFO'}) { - print "\n"; - } print_header_links($status); if (defined $site_html_head_string) { @@ -4234,7 +4242,7 @@ sub git_header_html { if (defined $logo) { print $cgi->a({-href => esc_url($logo_url), -title => $logo_label}, - $cgi->img({-src => esc_url($logo), + $cgi->img({-src => esc_url_base($logo), -width => 72, -height => 27, -alt => "git", -class => "logo"})); @@ -4299,7 +4307,7 @@ sub git_footer_html { insert_file($site_footer); } - print qq!\n!; + print qq!\n!; if (defined $action && $action eq 'blame_incremental') { print qq!