X-Git-Url: https://git.sesse.net/?p=pr0n;a=blobdiff_plain;f=perl%2FSesse%2Fpr0n%2FCommon.pm;h=43ea98853ffbd6e41f9e108512009d46063f1cb5;hp=6c3d7e4110545bb2ac4d43c908df2cf0e0b7865b;hb=4e9898a97f5c3c52d1277ed73cb4365b8644870a;hpb=f9ff3e7edda055056a4de903d4b959f8fa1c2542 diff --git a/perl/Sesse/pr0n/Common.pm b/perl/Sesse/pr0n/Common.pm index 6c3d7e4..43ea988 100644 --- a/perl/Sesse/pr0n/Common.pm +++ b/perl/Sesse/pr0n/Common.pm @@ -139,19 +139,45 @@ sub get_query_string { } return $str; } + +# This is not perfect (it can't handle "_ " right, for one), but it will do for now +sub weird_space_encode { + my $val = shift; + if ($val =~ /_/) { + return "_" x (length($val) * 2); + } else { + return "_" x (length($val) * 2 - 1); + } +} + +sub weird_space_unencode { + my $val = shift; + if (length($val) % 2 == 0) { + return "_" x (length($val) / 2); + } else { + return " " x ((length($val) + 1) / 2); + } +} sub pretty_escape { my $value = shift; + $value =~ s/(([_ ])\2*)/weird_space_encode($1)/ge; $value = URI::Escape::uri_escape($value); - - # Unescape a few for prettiness (we'll need something for a real _, though) - $value =~ s/%20/_/g; $value =~ s/%2F/\//g; return $value; } +sub pretty_unescape { + my $value = shift; + + # URI unescaping is already done for us + $value =~ s/(_+)/weird_space_unencode($1)/ge; + + return $value; +} + sub print_link { my ($r, $title, $baseurl, $param, $defparam, $accesskey) = @_; my $str = "