From: Tobias Girstmair <tobi@isticktoit.net> To: git@vger.kernel.org Cc: Tobias Girstmair <tobi@isticktoit.net> Subject: [PATCH v2] gitweb: Replace <base> 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> (raw) In-Reply-To: <20200711203947.23520-1-tobi@isticktoit.net> 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 <tobi@isticktoit.net> --- 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 <base> 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 . "<img width=\"$size\" " . "class=\"avatar\" " . - "src=\"".esc_url($url)."\" " . + "src=\"".esc_url_base($url)."\" " . "alt=\"\" " . "/>" . $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 '<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n"; + print '<link rel="stylesheet" type="text/css" href="'.esc_url_base($stylesheet).'"/>'."\n"; } else { foreach my $stylesheet (@stylesheets) { next unless $stylesheet; - print '<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n"; + print '<link rel="stylesheet" type="text/css" href="'.esc_url_base($stylesheet).'"/>'."\n"; } } print_feed_meta() if ($status eq '200 OK'); if (defined $favicon) { - print qq(<link rel="shortcut icon" href=").esc_url($favicon).qq(" type="image/png" />\n); + print qq(<link rel="shortcut icon" href=").esc_url_base($favicon).qq(" type="image/png" />\n); } } @@ -4212,11 +4225,6 @@ sub git_header_html { <meta name="robots" content="index, nofollow"/> <title>$title</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 "<base href=\"".esc_url($base_url)."\" />\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!<script type="text/javascript" src="!.esc_url($javascript).qq!"></script>\n!; + print qq!<script type="text/javascript" src="!.esc_url_base($javascript).qq!"></script>\n!; if (defined $action && $action eq 'blame_incremental') { print qq!<script type="text/javascript">\n!. @@ -8273,7 +8281,7 @@ sub git_feed { if (defined $logo || defined $favicon) { # prefer the logo to the favicon, since RSS # doesn't allow both - my $img = esc_url($logo || $favicon); + my $img = esc_url_base($logo || $favicon); print "<image>\n" . "<url>$img</url>\n" . "<title>$title</title>\n" . @@ -8299,11 +8307,11 @@ sub git_feed { # use project owner for feed author "<author><name>$owner</name></author>\n"; if (defined $favicon) { - print "<icon>" . esc_url($favicon) . "</icon>\n"; + print "<icon>" . esc_url_base($favicon) . "</icon>\n"; } if (defined $logo) { # not twice as wide as tall: 72 x 27 pixels - print "<logo>" . esc_url($logo) . "</logo>\n"; + print "<logo>" . esc_url_base($logo) . "</logo>\n"; } if (! %latest_date) { # dummy date to keep the feed valid until commits trickle in: -- 2.21.3
next prev parent reply other threads:[~2020-07-12 18:58 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-07-11 20:39 [PATCH] " Tobias Girstmair 2020-07-12 18:24 ` Tobias Girstmair [this message] 2020-07-12 18:33 ` [PATCH v3] " Tobias Girstmair 2020-07-12 21:00 ` Junio C Hamano 2020-07-12 23:05 ` Tobias Girstmair 2020-07-13 4:34 ` Junio C Hamano 2020-07-13 9:29 ` Tobias Girstmair 2020-07-13 14:44 ` Junio C Hamano 2020-07-13 14:59 ` Tobias Girstmair 2020-11-20 15:19 ` Tobias Girstmair
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: http://vger.kernel.org/majordomo-info.html * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200712182418.1696-1-tobi@isticktoit.net \ --to=tobi@isticktoit.net \ --cc=git@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
git@vger.kernel.org list mirror (unofficial, one of many) This inbox may be cloned and mirrored by anyone: git clone --mirror https://public-inbox.org/git git clone --mirror http://ou63pmih66umazou.onion/git git clone --mirror http://czquwvybam4bgbro.onion/git git clone --mirror http://hjrcffqmbrq6wope.onion/git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V1 git git/ https://public-inbox.org/git \ git@vger.kernel.org public-inbox-index git Example config snippet for mirrors. Newsgroups are available over NNTP: nntp://news.public-inbox.org/inbox.comp.version-control.git nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git nntp://news.gmane.io/gmane.comp.version-control.git note: .onion URLs require Tor: https://www.torproject.org/ code repositories for the project(s) associated with this inbox: https://80x24.org/mirrors/git.git AGPL code for this site: git clone https://public-inbox.org/public-inbox.git