From 5436435c3fc228d7861e4b3d23f8e9e90a541de0 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Sun, 16 Oct 2016 10:17:34 +0200 Subject: [PATCH] Improve handling of man names with special characters The 'source' link was broken for mans with [ or ] characters. All links were broken for mans with space characters. Man page of the week: https://manned.org/KGenericFactory_%20KTypeList_%20Product,%20ProductListTail%20_,%20KTypeList_%20ParentType,%20ParentTypeListTail%20_%20_/dfc33ca6 There's a 5 man pages left with a '%' or '#' character. I've no idea if it's worth handling those; A fix for these isn't going to be as trivial as this commit. --- www/index.pl | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/www/index.pl b/www/index.pl index a30e471..967ef0a 100755 --- a/www/index.pl +++ b/www/index.pl @@ -79,6 +79,7 @@ TUWF::register( # I'm not a fan of this solution; might drop it in the future. qr{lang/([^/]+)/([^/]+)} => sub { my($s, $l, $n) = @_; + $n = _normalizename($n); my($m, undef) = $s->dbManPrefName($n, language => $l); return $s->resNotFound if !$m; $s->resRedirect("/$m->{name}/".substr($m->{hash}, 0, 8), 'temp'); @@ -577,12 +578,21 @@ sub _man_langsect { } +sub _normalizename { + local $_ = shift; + # Firefox seems to escape [ and ] in URLs. It doesn't really have to... + s/%5b/[/ig; + s/%5d/]/ig; + # Man pages with spaces in the path, eww + s/%20/ /g; + $_; +} + + sub man { my($self, $name, $hash) = @_; - # Firefox seems to escape [ and ] in URLs. It doesn't really have to... - $name =~ s/%5b/[/ig; - $name =~ s/%5d/]/ig; + $name = _normalizename($name); my $man; if($hash) { @@ -617,6 +627,8 @@ sub man { sub src { my($self, $name, $hash) = @_; + $name = _normalizename($name); + my $m = $self->dbManInfo(name => $name, shorthash => $hash); return $self->resNotFound if !@$m;