]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
repobrowse: preserve newlines in Atom feed
authorEric Wong <e@80x24.org>
Sat, 21 Jan 2017 11:50:58 +0000 (11:50 +0000)
committerEric Wong <e@80x24.org>
Sat, 21 Jan 2017 11:52:16 +0000 (11:52 +0000)
Commit messages are assumed to be displayed in a terminal
with a fixed width font, so we must preserve newlines and
all whitespace as-is so ASCII art may be displayed properly.

lib/PublicInbox/RepobrowseGitAtom.pm
t/repobrowse_git_atom.t

index c542281c02c9533f53efadd5aeab37ae2ce24368..87fc60a7c174c860aedd0929676214beef642009 100644 (file)
@@ -81,6 +81,7 @@ sub git_atom_sed ($$) {
                qq(<link\nrel="alternate"\ntype="text/html"\nhref="$url"\n/>);
        my ($plinks, $id, $ai);
        my $end = '';
+       my $blines;
        sub {
                my $dst;
                # $_[0] == scalar buffer, undef means EOF from "git log"
@@ -102,6 +103,7 @@ sub git_atom_sed ($$) {
                                if (++$state == STATE_BODY) {
                                        flush_hdr(\$dst, $hdr, $url);
                                        $hdr = {};
+                                       $blines = 0;
                                }
                                next;
                        }
@@ -109,6 +111,7 @@ sub git_atom_sed ($$) {
                                $dst .= qq(</pre></div></content></entry>);
                                $state = 0;
                        } else {
+                               $dst .= "\n" if $blines++;
                                $dst .= utf8_html($l);
                        }
                }
index 4f0078ebbd498479f762c0325661e650ae5aa658..1f8e95e3c1c648d857f9e0f2567d54daac43c30d 100644 (file)
@@ -20,6 +20,8 @@ test_psgi($test->{app}, sub {
                is($p->format, "Atom", "parsed atom feed");
                is(scalar $p->entries, 6, "parsed six entries");
        }
+       like($body, qr!<pre\s*[^>]+>\* header:\n  add header</pre>!,
+               'body wrapped in <pre>');
 
        $res = $cb->(GET($req . '/'));
        my $sl = dechunk($res);