From 22d8fcc3d37b9ce13a5088f1d0557078c9a84062 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 2 Oct 2015 21:15:07 +0000 Subject: rename mid_compress to id_compress We use it as a general compressor for identifiers such as subject paths, so using the "mid_" prefix probably is not appropriate. --- lib/PublicInbox/MID.pm | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'lib/PublicInbox/MID.pm') diff --git a/lib/PublicInbox/MID.pm b/lib/PublicInbox/MID.pm index 677a9d59..3d404ef8 100644 --- a/lib/PublicInbox/MID.pm +++ b/lib/PublicInbox/MID.pm @@ -4,7 +4,7 @@ package PublicInbox::MID; use strict; use warnings; use base qw/Exporter/; -our @EXPORT_OK = qw/mid_clean mid_compress mid2path/; +our @EXPORT_OK = qw/mid_clean id_compress mid2path/; use Digest::SHA qw/sha1_hex/; use constant MID_MAX => 40; # SHA-1 hex length @@ -19,18 +19,13 @@ sub mid_clean { } # this is idempotent -sub mid_compress { - my ($mid, $force) = @_; +sub id_compress { + my ($id, $force) = @_; - # XXX dirty hack! FIXME! - # Some HTTP servers (apache2 2.2.22-13+deb7u5 on my system) - # apparently do not handle "%25" in the URL path component correctly. - # I'm not yet sure if it's something weird with my rewrite rules - # or what; will need to debug... - return sha1_hex($mid) if (index($mid, '%') >= 0); - - return $mid if (!$force && length($mid) <= MID_MAX); - sha1_hex($mid); + if ($force || $id =~ /[^\w\-]/ || length($id) > MID_MAX) { + return sha1_hex($id); + } + $id; } sub mid2path { -- cgit v1.2.3-24-ge0c7