* [PATCH 0/5] view*: minor cleanups and fixes
@ 2020-04-04 8:03 Eric Wong
2020-04-04 8:03 ` [PATCH 1/5] view: note we assume UTF-8 on unknown encodings Eric Wong
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Eric Wong @ 2020-04-04 8:03 UTC (permalink / raw)
To: meta
Just a few odds and ends which bother me when reading
the code or render HTML result.
Eric Wong (5):
view: note we assume UTF-8 on unknown encodings
view: use defined-or operator to simplify checks
view: dedupe_subject: allow "0" is a valid Subject
viewdiff: reduce sub parameter count
view: inline flush_quote sub
lib/PublicInbox/View.pm | 37 +++++++++++++++----------------------
lib/PublicInbox/ViewDiff.pm | 21 ++++++++++++---------
2 files changed, 27 insertions(+), 31 deletions(-)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/5] view: note we assume UTF-8 on unknown encodings
2020-04-04 8:03 [PATCH 0/5] view*: minor cleanups and fixes Eric Wong
@ 2020-04-04 8:03 ` Eric Wong
2020-04-04 8:03 ` [PATCH 2/5] view: use defined-or operator to simplify checks Eric Wong
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2020-04-04 8:03 UTC (permalink / raw)
To: meta
Clarify that we're assuming the text is UTF-8, since users
may have no idea how it's mangled.
---
lib/PublicInbox/View.pm | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 70c10604..d897aeec 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -518,7 +518,9 @@ sub attach_link ($$$$;$) {
my $rv = $ctx->{obuf};
$$rv .= qq($nl<a\nhref="$ctx->{mhref}$idx-$sfn">);
if ($err) {
- $$rv .= "[-- Warning: decoded text below may be mangled --]\n";
+ $$rv .= <<EOF;
+[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
+EOF
}
$$rv .= "[-- Attachment #$idx: ";
my $ts = "Type: $ct, Size: $size bytes";
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/5] view: use defined-or operator to simplify checks
2020-04-04 8:03 [PATCH 0/5] view*: minor cleanups and fixes Eric Wong
2020-04-04 8:03 ` [PATCH 1/5] view: note we assume UTF-8 on unknown encodings Eric Wong
@ 2020-04-04 8:03 ` Eric Wong
2020-04-04 8:03 ` [PATCH 3/5] view: dedupe_subject: allow "0" is a valid Subject Eric Wong
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2020-04-04 8:03 UTC (permalink / raw)
To: meta
We depend on Perl 5.10 features in other places. Shorten the
lifetime of the `$desc' scalar while we're at it.
---
lib/PublicInbox/View.pm | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index d897aeec..9ef1f68a 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -504,9 +504,6 @@ sub attach_link ($$$$;$) {
# spotting MUA problems:
$ct =~ s/;.*// unless $err;
$ct = ascii_html($ct);
- my $desc = $part->header('Content-Description');
- $desc = $fn unless defined $desc;
- $desc = '' unless defined $desc;
my $sfn;
if (defined $fn && $fn =~ /\A$PublicInbox::Hval::FN\z/o) {
$sfn = $fn;
@@ -524,6 +521,7 @@ EOF
}
$$rv .= "[-- Attachment #$idx: ";
my $ts = "Type: $ct, Size: $size bytes";
+ my $desc = $part->header('Content-Description') // $fn // '';
$desc = ascii_html($desc);
$$rv .= ($desc eq '') ? "$ts --]" : "$desc --]\n[-- $ts --]";
$$rv .= "</a>\n";
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/5] view: dedupe_subject: allow "0" is a valid Subject
2020-04-04 8:03 [PATCH 0/5] view*: minor cleanups and fixes Eric Wong
2020-04-04 8:03 ` [PATCH 1/5] view: note we assume UTF-8 on unknown encodings Eric Wong
2020-04-04 8:03 ` [PATCH 2/5] view: use defined-or operator to simplify checks Eric Wong
@ 2020-04-04 8:03 ` Eric Wong
2020-04-04 23:38 ` Eric Wong
2020-04-04 8:03 ` [PATCH 4/5] viewdiff: reduce sub parameter count Eric Wong
2020-04-04 8:03 ` [PATCH 5/5] view: inline flush_quote sub Eric Wong
4 siblings, 1 reply; 7+ messages in thread
From: Eric Wong @ 2020-04-04 8:03 UTC (permalink / raw)
To: meta
While rare in practice (even by spammers), A single "0" could
theoretically be the entire contents of a Subject line. So
use the Perl 5.10+ defined-or operator to improve correctness
of subject deduplication.
---
lib/PublicInbox/View.pm | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 9ef1f68a..f0584cb7 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -888,20 +888,20 @@ sub missing_thread {
sub dedupe_subject {
my ($prev_subj, $subj, $val) = @_;
- my $omit = ''; # '"' denotes identical text omitted
+ my $omit; # '"' denotes identical text omitted
my (@prev_pop, @curr_pop);
while (@$prev_subj && @$subj && $subj->[-1] eq $prev_subj->[-1]) {
push(@prev_pop, pop(@$prev_subj));
push(@curr_pop, pop(@$subj));
- $omit ||= $val;
+ $omit //= $val;
}
pop @$subj if @$subj && $subj->[-1] =~ /^re:\s*/i;
if (scalar(@curr_pop) == 1) {
- $omit = '';
+ $omit = undef;
push @$prev_subj, @prev_pop;
push @$subj, @curr_pop;
}
- $omit;
+ $omit // '';
}
sub skel_dump { # walk_thread callback
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/5] viewdiff: reduce sub parameter count
2020-04-04 8:03 [PATCH 0/5] view*: minor cleanups and fixes Eric Wong
` (2 preceding siblings ...)
2020-04-04 8:03 ` [PATCH 3/5] view: dedupe_subject: allow "0" is a valid Subject Eric Wong
@ 2020-04-04 8:03 ` Eric Wong
2020-04-04 8:03 ` [PATCH 5/5] view: inline flush_quote sub Eric Wong
4 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2020-04-04 8:03 UTC (permalink / raw)
To: meta
We're slowly moving towards doing all of our output buffering
into a single buffer, so passing that around on the stack as
a dedicated parameter is confusing.
---
lib/PublicInbox/View.pm | 2 +-
lib/PublicInbox/ViewDiff.pm | 21 ++++++++++++---------
2 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index f0584cb7..12ef6431 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -589,7 +589,7 @@ sub add_text_body { # callback for msg_iter
if ($cur =~ /\A>/) {
flush_quote($rv, $l, \$cur);
} elsif ($diff) {
- flush_diff($rv, $ctx, \$cur);
+ flush_diff($ctx, \$cur);
} else {
# regular lines, OK
$$rv .= $l->to_html($cur);
diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm
index 5d391a13..f7422712 100644
--- a/lib/PublicInbox/ViewDiff.pm
+++ b/lib/PublicInbox/ViewDiff.pm
@@ -120,8 +120,8 @@ sub anchor1 ($$) {
$ok ? "<a\nhref=#i$attr\nid=$attr>diff</a> --git" : undef
}
-sub diff_header ($$$$) {
- my ($dst, $x, $ctx, $top) = @_;
+sub diff_header ($$$) {
+ my ($x, $ctx, $top) = @_;
my (undef, undef, $pa, $pb) = splice(@$top, 0, 4); # ignore oid_{a,b}
my $spfx = $ctx->{-spfx};
my $dctx = { spfx => $spfx };
@@ -159,15 +159,17 @@ sub diff_header ($$$$) {
warn "BUG? <$$x> had no ^index line";
}
$$x =~ s!^diff --git!anchor1($ctx, $pb) // 'diff --git'!ems;
+ my $dst = $ctx->{obuf};
$$dst .= qq(<span\nclass="head">);
$$dst .= $$x;
$$dst .= '</span>';
$dctx;
}
-sub diff_before_or_after ($$$) {
- my ($dst, $ctx, $x) = @_;
+sub diff_before_or_after ($$) {
+ my ($ctx, $x) = @_;
my $linkify = $ctx->{-linkify};
+ my $dst = $ctx->{obuf};
for my $y (split(/(^---\n)/sm, $$x)) {
if ($y =~ /\A---\n\z/s) {
$$dst .= "---\n"; # all HTML is "\r\n" => "\n"
@@ -186,20 +188,21 @@ sub diff_before_or_after ($$$) {
}
# callers must do CRLF => LF conversion before calling this
-sub flush_diff ($$$) {
- my ($dst, $ctx, $cur) = @_;
+sub flush_diff ($$) {
+ my ($ctx, $cur) = @_;
my @top = split($EXTRACT_DIFFS, $$cur);
$$cur = undef;
my $linkify = $ctx->{-linkify};
+ my $dst = $ctx->{obuf};
my $dctx; # {}, keys: Q, oid_a, oid_b
while (defined(my $x = shift @top)) {
if (scalar(@top) >= 4 &&
$top[1] =~ $IS_OID &&
$top[0] =~ $IS_OID) {
- $dctx = diff_header($dst, \$x, $ctx, \@top);
+ $dctx = diff_header(\$x, $ctx, \@top);
} elsif ($dctx) {
my $after = '';
@@ -238,9 +241,9 @@ sub flush_diff ($$$) {
$$dst .= $linkify->to_html($s);
}
}
- diff_before_or_after($dst, $ctx, \$after) unless $dctx;
+ diff_before_or_after($ctx, \$after) unless $dctx;
} else {
- diff_before_or_after($dst, $ctx, \$x);
+ diff_before_or_after($ctx, \$x);
}
}
}
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/5] view: inline flush_quote sub
2020-04-04 8:03 [PATCH 0/5] view*: minor cleanups and fixes Eric Wong
` (3 preceding siblings ...)
2020-04-04 8:03 ` [PATCH 4/5] viewdiff: reduce sub parameter count Eric Wong
@ 2020-04-04 8:03 ` Eric Wong
4 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2020-04-04 8:03 UTC (permalink / raw)
To: meta
No point in having an extra sub for a short, commonly
called function in the same file.
---
lib/PublicInbox/View.pm | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 12ef6431..1e53d8dc 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -482,17 +482,6 @@ sub multipart_text_as_html {
msg_iter($_[0], \&add_text_body, $_[1], 1);
}
-sub flush_quote {
- my ($s, $l, $quot) = @_;
-
- my $rv = $l->to_html($$quot);
-
- # we use a <span> here to allow users to specify their own
- # color for quoted text
- $$quot = undef;
- $$s .= qq(<span\nclass="q">) . $rv . '</span>'
-}
-
sub attach_link ($$$$;$) {
my ($ctx, $ct, $p, $fn, $err) = @_;
my ($part, $depth, @idx) = @$p;
@@ -587,14 +576,18 @@ sub add_text_body { # callback for msg_iter
my $l = $ctx->{-linkify} //= PublicInbox::Linkify->new;
foreach my $cur (@sections) {
if ($cur =~ /\A>/) {
- flush_quote($rv, $l, \$cur);
+ # we use a <span> here to allow users to specify
+ # their own color for quoted text
+ $$rv .= qq(<span\nclass="q">);
+ $$rv .= $l->to_html($cur);
+ $$rv .= '</span>';
} elsif ($diff) {
flush_diff($ctx, \$cur);
} else {
# regular lines, OK
$$rv .= $l->to_html($cur);
- $cur = undef;
}
+ $cur = undef;
}
obfuscate_addrs($ibx, $$rv) if $ibx->{obfuscate};
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 3/5] view: dedupe_subject: allow "0" is a valid Subject
2020-04-04 8:03 ` [PATCH 3/5] view: dedupe_subject: allow "0" is a valid Subject Eric Wong
@ 2020-04-04 23:38 ` Eric Wong
0 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2020-04-04 23:38 UTC (permalink / raw)
To: meta
$subject =~ s/is/as/
That should be:
Subject: [PATCH 3/5] view: dedupe_subject: allow "0" as a valid Subject
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-04-04 23:38 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-04 8:03 [PATCH 0/5] view*: minor cleanups and fixes Eric Wong
2020-04-04 8:03 ` [PATCH 1/5] view: note we assume UTF-8 on unknown encodings Eric Wong
2020-04-04 8:03 ` [PATCH 2/5] view: use defined-or operator to simplify checks Eric Wong
2020-04-04 8:03 ` [PATCH 3/5] view: dedupe_subject: allow "0" is a valid Subject Eric Wong
2020-04-04 23:38 ` Eric Wong
2020-04-04 8:03 ` [PATCH 4/5] viewdiff: reduce sub parameter count Eric Wong
2020-04-04 8:03 ` [PATCH 5/5] view: inline flush_quote sub Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).