projects
/
pr0n
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
e3d1e1f
)
Fiddle a bit with the pretty-escaping.
author
Steinar H. Gunderson
<sesse@debian.org>
Thu, 26 Jul 2007 00:03:45 +0000
(
02:03
+0200)
committer
Steinar H. Gunderson
<sesse@debian.org>
Thu, 26 Jul 2007 00:03:45 +0000
(
02:03
+0200)
perl/Sesse/pr0n/Common.pm
patch
|
blob
|
history
diff --git
a/perl/Sesse/pr0n/Common.pm
b/perl/Sesse/pr0n/Common.pm
index 098c9d36d22ea766ce6f828dc6f0633f15fa00a6..43ea98853ffbd6e41f9e108512009d46063f1cb5 100644
(file)
--- a/
perl/Sesse/pr0n/Common.pm
+++ b/
perl/Sesse/pr0n/Common.pm
@@
-139,14
+139,31
@@
sub get_query_string {
}
return $str;
}
}
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;
sub pretty_escape {
my $value = shift;
+ $value =~ s/(([_ ])\2*)/weird_space_encode($1)/ge;
$value = URI::Escape::uri_escape($value);
$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;
$value =~ s/%2F/\//g;
return $value;
@@
-156,7
+173,7
@@
sub pretty_unescape {
my $value = shift;
# URI unescaping is already done for us
my $value = shift;
# URI unescaping is already done for us
- $value =~ s/
_/ /g
;
+ $value =~ s/
(_+)/weird_space_unencode($1)/ge
;
return $value;
}
return $value;
}