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.
This commit is contained in:
Yorhel 2016-10-16 10:17:34 +02:00
parent 8a0fac08b6
commit 5436435c3f

View file

@ -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;