]> Sergey Matveev's repositories - public-inbox.git/commitdiff
hval: to_attr: support wide characters
authorEric Wong <e@yhbt.net>
Sun, 19 Jan 2020 09:40:51 +0000 (09:40 +0000)
committerEric Wong <e@yhbt.net>
Thu, 23 Jan 2020 23:04:04 +0000 (23:04 +0000)
We need to escape wide characters when making attribute names from
filename-looking things in diffstats.

lib/PublicInbox/Hval.pm
t/solve/0001-simple-mod.patch
t/solver_git.t

index 7e007027c8ba9d27fc58cf6c6d942b83b1d18c4f..39256ee01e0380bdfafd8c655265a82ceb796100 100644 (file)
@@ -139,10 +139,12 @@ sub to_attr ($) {
        return if index($str, '//') >= 0;
 
        my $first = '';
+       utf8::encode($str); # to octets
        if ($str =~ s/\A([^A-Ya-z])//ms) { # start with a letter
                  $first = sprintf('Z%02x', ord($1));
        }
        $str =~ s/([^A-Za-z0-9_\.\-])/$ESCAPES{$1}/egms;
+       utf8::decode($str); # allow wide chars
        $first . $str;
 }
 
@@ -155,6 +157,7 @@ sub from_attr ($) {
        }
        $str =~ s!::([a-f0-9]{2})!chr(hex($1))!egms;
        $str =~ tr!:!/!;
+       utf8::decode($str);
        $first . $str;
 }
 
index c6bb1575d843dd4291c85105c3c866921e69920a..c55fe310ce0eef9277ab379d65ba1d1a5e093d94 100644 (file)
@@ -3,9 +3,11 @@ To: meta@public-inbox.org
 Subject: [PATCH] TODO: take expert web design advice
 Date: Mon, 1 Apr 2019 08:15:20 +0000
 Message-Id: <20190401081523.16213-1-BOFH@YHBT.net>
+Content-Type: text/plain; charset=utf-8
 
 ---
  TODO | 2 ++
+ Ω    | 5 --
  1 file changed, 2 insertions(+)
 
 diff --git a/TODO b/TODO
index 92402c3a16768b88aea7347254cfcb9f2a78952f..92c073345a5e70926227d38b729932db2d0f60c9 100644 (file)
@@ -154,7 +154,16 @@ EOF
        my $non_existent = 'ee5e32211bf62ab6531bdf39b84b6920d0b6775a';
        my $client = sub {
                my ($cb) = @_;
-               my $res = $cb->(GET("/$name/3435775/s/"));
+               my $mid = '20190401081523.16213-1-BOFH@YHBT.net';
+               my @warn;
+               my $res = do {
+                       local $SIG{__WARN__} = sub { push @warn, @_ };
+                       $cb->(GET("/$name/$mid/"));
+               };
+               is_deeply(\@warn, [], 'no warnings from rendering diff');
+               like($res->content, qr!>&#937;</a>!, 'omega escaped');
+
+               $res = $cb->(GET("/$name/3435775/s/"));
                is($res->code, 200, 'success with existing blob');
 
                $res = $cb->(GET("/$name/".('0'x40).'/s/'));