]> Sergey Matveev's repositories - public-inbox.git/commitdiff
treat $INBOX_DIR/description and gitweb.owner as UTF-8
authorEric Wong <e@yhbt.net>
Thu, 28 May 2020 18:37:08 +0000 (18:37 +0000)
committerEric Wong <e@yhbt.net>
Fri, 29 May 2020 19:01:04 +0000 (19:01 +0000)
gitweb does the same with $GIT_DIR/description and gitweb.owner.

Allowing UTF-8 description should not cause problems when used
in responses for to the NNTP "LIST NEWSGROUPS" request, either,
since RFC 3977 section 7.6.6 recommends the description be UTF-8
(but does not require it).

Link: https://public-inbox.org/meta/20200528151216.l7vmnmrs4ojw372g@sourcephile.fr/
lib/PublicInbox/Inbox.pm
lib/PublicInbox/WwwListing.pm
t/inbox.t
t/www_listing.t

index 002b980f40574e266dfc68b065e8bd733016eb4d..c295b2677e48299cbfbacfc53f36136ad73f479f 100644 (file)
@@ -223,6 +223,7 @@ sub description {
                my $desc = try_cat("$self->{inboxdir}/description");
                local $/ = "\n";
                chomp $desc;
+               utf8::decode($desc);
                $desc =~ s/\s+/ /smg;
                $desc eq '' ? undef : $desc;
        }) // '($INBOX_DIR/description missing)';
index 38a37ddaae977f129081f4b054f4ac9a1076385b..a416d24f0e446e27ae3c3148b061be9128ca7350 100644 (file)
@@ -159,6 +159,8 @@ sub manifest_add ($$;$$) {
        chomp(my $desc = try_cat("$git_dir/description"));
        $owner = undef if $owner eq '';
        $desc = 'Unnamed repository' if $desc eq '';
+       utf8::decode($desc);
+       utf8::decode($owner);
 
        # templates/hooks--update.sample and git-multimail in git.git
        # only match "Unnamed repository", not the full contents of
index b59d5dba8c0fbd1c6000b06175f97d136a43ad3c..08f1724f092698bb76b1e8deeb30b68a8c5392b9 100644 (file)
--- a/t/inbox.t
+++ b/t/inbox.t
@@ -22,13 +22,14 @@ is($x->description, '($INBOX_DIR/description missing)', 'default description');
        print $fh "https://example.com/inbox\n" or die;
        close $fh or die;
        open $fh, '>', "$x->{inboxdir}/description" or die;
-       print $fh "blah\n" or die;
+       print $fh "\xc4\x80blah\n" or die;
        close $fh or die;
 }
 is_deeply($x->cloneurl, ['https://example.com/inbox'], 'cloneurls update');
-is($x->description, 'blah', 'description updated');
+ok(utf8::valid($x->description), 'description is utf8::valid');
+is($x->description, "\x{100}blah", 'description updated');
 is(unlink(glob("$x->{inboxdir}/*")), 2, 'unlinked cloneurl & description');
 is_deeply($x->cloneurl, ['https://example.com/inbox'], 'cloneurls memoized');
-is($x->description, 'blah', 'description memoized');
+is($x->description, "\x{100}blah", 'description memoized');
 
 done_testing();
index 31d76356d886697093a099129fddf22e1b5e50ad..0aededd43ebc669b211ebbd366ec8bec770e85d8 100644 (file)
@@ -46,7 +46,7 @@ sub tiny_test {
        unlike($tmp, qr/"modified":\s*"/, 'modified is an integer');
        my $manifest = $json->decode($tmp);
        ok(my $clone = $manifest->{'/alt'}, '/alt in manifest');
-       is($clone->{owner}, 'lorelei', 'owner set');
+       is($clone->{owner}, "lorelei \x{100}", 'owner set');
        is($clone->{reference}, '/bare', 'reference detected');
        is($clone->{description}, "we're all clones", 'description read');
        ok(my $bare = $manifest->{'/bare'}, '/bare in manifest');
@@ -88,7 +88,8 @@ SKIP: {
        open $fh, '>', "$alt/description" or die;
        print $fh "we're all clones\n" or die;
        close $fh or die;
-       is(xsys('git', "--git-dir=$alt", qw(config gitweb.owner lorelei)), 0,
+       is(xsys('git', "--git-dir=$alt", qw(config gitweb.owner),
+               "lorelei \xc4\x80"), 0,
                'set gitweb user');
        ok(unlink("$bare->{git_dir}/description"), 'removed bare/description');
        open $fh, '>', $cfgfile or die;