user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH 0/5] uninitialized vs blank fixes
@ 2020-07-07 20:37 Eric Wong
  2020-07-07 20:37 ` [PATCH 1/5] viewvcs: allow "0" as a path name Eric Wong
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Eric Wong @ 2020-07-07 20:37 UTC (permalink / raw)
  To: meta

This quiets some uninitialized variable warnings in various
places and includes minor fixes around "//" vs "||".

Eric Wong (5):
  viewvcs: allow "0" as a path name
  hval: to_filename: return `undef' instead of empty string
  viewvcs: stop checking unused "B" query parameter
  imap: avoid warnings on non-slice mailboxes
  wwwatomstream: avoid uninitialized warnings for $email

 lib/PublicInbox/Hval.pm          |  4 ++--
 lib/PublicInbox/IMAP.pm          |  1 +
 lib/PublicInbox/Mbox.pm          |  4 ++--
 lib/PublicInbox/MboxGz.pm        |  3 +--
 lib/PublicInbox/SolverGit.pm     |  2 +-
 lib/PublicInbox/ViewVCS.pm       |  8 +++++---
 lib/PublicInbox/WWW.pm           |  5 ++---
 lib/PublicInbox/WwwAtomStream.pm | 13 +++++--------
 t/hval.t                         |  8 +++++---
 t/imapd.t                        |  4 ++++
 10 files changed, 28 insertions(+), 24 deletions(-)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] viewvcs: allow "0" as a path name
  2020-07-07 20:37 [PATCH 0/5] uninitialized vs blank fixes Eric Wong
@ 2020-07-07 20:37 ` Eric Wong
  2020-07-07 20:37 ` [PATCH 2/5] hval: to_filename: return `undef' instead of empty string Eric Wong
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2020-07-07 20:37 UTC (permalink / raw)
  To: meta

This means we need to filter out "" from query parameters.
While we're at it, update comments for the WWW endpoint.
---
 lib/PublicInbox/ViewVCS.pm | 6 ++++--
 lib/PublicInbox/WWW.pm     | 5 ++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index 9ec04f480..053848a8b 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -127,7 +127,7 @@ sub solve_result {
 
 	my ($git, $oid, $type, $size, $di) = @$res;
 	return show_other($ctx, $res, \$log, $fn) if $type ne 'blob';
-	my $path = to_filename($di->{path_b} || $hints->{path_b} || 'blob');
+	my $path = to_filename($di->{path_b} // $hints->{path_b} // 'blob');
 	my $raw_link = "(<a\nhref=$path>raw</a>)";
 	if ($size > $MAX_SIZE) {
 		return stream_large_blob($ctx, $res, \$log, $fn) if defined $fn;
@@ -184,13 +184,15 @@ sub solve_result {
 	html_page($ctx, 200, \$log);
 }
 
+# GET /$INBOX/$GIT_OBJECT_ID/s/
+# GET /$INBOX/$GIT_OBJECT_ID/s/$FILENAME
 sub show ($$;$) {
 	my ($ctx, $oid_b, $fn) = @_;
 	my $qp = $ctx->{qp};
 	my $hints = $ctx->{hints} = {};
 	while (my ($from, $to) = each %QP_MAP) {
 		defined(my $v = $qp->{$from}) or next;
-		$hints->{$to} = $v;
+		$hints->{$to} = $v if $v ne '';
 	}
 
 	$ctx->{'log'} = tmpfile("solve.$oid_b");
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index e4ad515a4..2ea5d80db 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -301,9 +301,8 @@ sub get_text {
 }
 
 # show git objects (blobs and commits)
-# /$INBOX/_/$OBJECT_ID/show
-# /$INBOX/_/${OBJECT_ID}_${FILENAME}
-# KEY may contain slashes
+# /$INBOX/$GIT_OBJECT_ID/s/
+# /$INBOX/$GIT_OBJECT_ID/s/$FILENAME
 sub get_vcs_object ($$$;$) {
 	my ($ctx, $inbox, $oid, $filename) = @_;
 	my $r404 = invalid_inbox($ctx, $inbox);

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/5] hval: to_filename: return `undef' instead of empty string
  2020-07-07 20:37 [PATCH 0/5] uninitialized vs blank fixes Eric Wong
  2020-07-07 20:37 ` [PATCH 1/5] viewvcs: allow "0" as a path name Eric Wong
@ 2020-07-07 20:37 ` Eric Wong
  2020-07-07 20:37 ` [PATCH 3/5] viewvcs: stop checking unused "B" query parameter Eric Wong
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2020-07-07 20:37 UTC (permalink / raw)
  To: meta

Returning an empty string for a filename makes no sense,
so instead return `undef' so the caller can setup a fallback
using the "//" operator.

This fixes uninitialized variable warnings because split()
on an empty string returns `undef', which caused to_filename
to warn on s// and tr// ops.
---
 lib/PublicInbox/Hval.pm   | 4 ++--
 lib/PublicInbox/Mbox.pm   | 4 ++--
 lib/PublicInbox/MboxGz.pm | 3 +--
 t/hval.t                  | 8 +++++---
 4 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm
index 46a839160..e21a64a60 100644
--- a/lib/PublicInbox/Hval.pm
+++ b/lib/PublicInbox/Hval.pm
@@ -94,12 +94,12 @@ sub obfuscate_addrs ($$;$) {
 
 # like format_sanitized_subject in git.git pretty.c with '%f' format string
 sub to_filename ($) {
-	my ($s, undef) = split(/\n/, $_[0]);
+	my $s = (split(/\n/, $_[0]))[0] // return; # empty string => undef
 	$s =~ s/[^A-Za-z0-9_\.]+/-/g;
 	$s =~ tr/././s;
 	$s =~ s/[\.\-]+\z//;
 	$s =~ s/\A[\.\-]+//;
-	$s
+	$s eq '' ? undef : $s;
 }
 
 # convert a filename (or any string) to HTML attribute
diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index 8726b9f64..115321c61 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -52,9 +52,9 @@ sub async_eml { # ->{async_eml} for async_blob_cb
 
 sub res_hdr ($$) {
 	my ($ctx, $subject) = @_;
-	my $fn = $subject // 'no-subject';
+	my $fn = $subject // '';
 	$fn =~ s/^re:\s+//i;
-	$fn = $fn eq '' ? 'no-subject' : to_filename($fn);
+	$fn = to_filename($fn) // 'no-subject';
 	my @hdr = ('Content-Type');
 	if ($ctx->{-inbox}->{obfuscate}) {
 		# obfuscation is stupid, but maybe scrapers are, too...
diff --git a/lib/PublicInbox/MboxGz.pm b/lib/PublicInbox/MboxGz.pm
index fdd16f68e..967af9c68 100644
--- a/lib/PublicInbox/MboxGz.pm
+++ b/lib/PublicInbox/MboxGz.pm
@@ -24,8 +24,7 @@ sub mbox_gz {
 	$self->{cb} = $cb;
 	$self->{base_url} = $self->{-inbox}->base_url($self->{env});
 	$self->{gz} = PublicInbox::GzipFilter::gzip_or_die();
-	$fn = to_filename($fn // 'no-subject');
-	$fn = 'no-subject' if $fn eq '';
+	$fn = to_filename($fn // '') // 'no-subject';
 	# http://www.iana.org/assignments/media-types/application/gzip
 	bless $self, __PACKAGE__;
 	my $res_hdr = [ 'Content-Type' => 'application/gzip',
diff --git a/t/hval.t b/t/hval.t
index 38605c6f1..e80a02ff4 100644
--- a/t/hval.t
+++ b/t/hval.t
@@ -47,15 +47,17 @@ EOF
 
 is($html, $exp, 'only obfuscated relevant addresses');
 
-is('foo-bar', PublicInbox::Hval::to_filename('foo bar  '),
+is(PublicInbox::Hval::to_filename('foo bar  '), 'foo-bar',
 	'to_filename has no trailing -');
 
-is('foo-bar', PublicInbox::Hval::to_filename("foo   bar\nanother line\n"),
+is(PublicInbox::Hval::to_filename("foo   bar\nanother line\n"), 'foo-bar',
 	'to_filename has no repeated -, and nothing past LF');
 
-is('foo.bar', PublicInbox::Hval::to_filename("foo....bar"),
+is(PublicInbox::Hval::to_filename("foo....bar"), 'foo.bar',
 	'to_filename squeezes -');
 
+is(PublicInbox::Hval::to_filename(''), undef, 'empty string returns undef');
+
 my $s = "\0\x07\n";
 PublicInbox::Hval::src_escape($s);
 is($s, "\\0\\a\n", 'src_escape works as intended');

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/5] viewvcs: stop checking unused "B" query parameter
  2020-07-07 20:37 [PATCH 0/5] uninitialized vs blank fixes Eric Wong
  2020-07-07 20:37 ` [PATCH 1/5] viewvcs: allow "0" as a path name Eric Wong
  2020-07-07 20:37 ` [PATCH 2/5] hval: to_filename: return `undef' instead of empty string Eric Wong
@ 2020-07-07 20:37 ` Eric Wong
  2020-07-07 20:37 ` [PATCH 4/5] imap: avoid warnings on non-slice mailboxes Eric Wong
  2020-07-07 20:37 ` [PATCH 5/5] wwwatomstream: avoid uninitialized warnings for $email Eric Wong
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2020-07-07 20:37 UTC (permalink / raw)
  To: meta

The resulting OID ("oid_b") is a required arg and part of
$env->{PATH_INFO}, instead; so it's never part of an optional
query parameter.
---
 lib/PublicInbox/SolverGit.pm | 2 +-
 lib/PublicInbox/ViewVCS.pm   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm
index b1cb1ae97..ddf5fa16b 100644
--- a/lib/PublicInbox/SolverGit.pm
+++ b/lib/PublicInbox/SolverGit.pm
@@ -594,7 +594,7 @@ sub new {
 }
 
 # recreate $oid_want using $hints
-# hints keys: path_a, path_b, oid_a
+# hints keys: path_a, path_b, oid_a (note: `oid_b' is NOT a hint)
 # Calls {user_cb} with: [ ::Git object, oid_full, type, size, di (diff_info) ]
 # with found object, or undef if nothing was found
 # Calls {user_cb} with a string error on fatal errors
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index 053848a8b..87927d5ea 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -27,7 +27,7 @@ my $hl = eval {
 	PublicInbox::HlMod->new;
 };
 
-my %QP_MAP = ( A => 'oid_a', B => 'oid_b', a => 'path_a', b => 'path_b' );
+my %QP_MAP = ( A => 'oid_a', a => 'path_a', b => 'path_b' );
 our $MAX_SIZE = 1024 * 1024; # TODO: configurable
 my $BIN_DETECT = 8000; # same as git
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/5] imap: avoid warnings on non-slice mailboxes
  2020-07-07 20:37 [PATCH 0/5] uninitialized vs blank fixes Eric Wong
                   ` (2 preceding siblings ...)
  2020-07-07 20:37 ` [PATCH 3/5] viewvcs: stop checking unused "B" query parameter Eric Wong
@ 2020-07-07 20:37 ` Eric Wong
  2020-07-07 20:37 ` [PATCH 5/5] wwwatomstream: avoid uninitialized warnings for $email Eric Wong
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2020-07-07 20:37 UTC (permalink / raw)
  To: meta

Non-slice mailboxes never have messages themselves,
so we must not assume a message exists when sending
untagged EXISTS messages.
---
 lib/PublicInbox/IMAP.pm | 1 +
 t/imapd.t               | 4 ++++
 2 files changed, 5 insertions(+)

diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm
index d8c898f4b..8ab4b1e7d 100644
--- a/lib/PublicInbox/IMAP.pm
+++ b/lib/PublicInbox/IMAP.pm
@@ -246,6 +246,7 @@ sub uo2m_extend ($$;$) {
 	my $base = $self->{uid_base};
 	++$beg;
 	my $uids = $self->{ibx}->over->uid_range($beg, $base + UID_SLICE);
+	return $uo2m if !scalar(@$uids);
 	my @tmp; # [$UID_OFFSET] => $MSN
 	my $write_method = $_[2] // 'msg_more';
 	if (ref($uo2m)) {
diff --git a/t/imapd.t b/t/imapd.t
index 1ac6a4ab6..6cfced411 100644
--- a/t/imapd.t
+++ b/t/imapd.t
@@ -87,12 +87,16 @@ my $post_auth_anon_capa = $mic->capability;
 is_deeply($post_auth_anon_capa, $post_login_capa,
 	'auth anon has same capabilities');
 my $e;
+ok($mic->noop, 'NOOP');
+ok($mic->noop, 'NOOP (again)'); # for warnings
 ok(!$mic->examine('foo') && ($e = $@), 'EXAMINE non-existent');
 like($e, qr/\bNO\b/, 'got a NO on EXAMINE for non-existent');
 ok(!$mic->select('foo') && ($e = $@), 'EXAMINE non-existent');
 like($e, qr/\bNO\b/, 'got a NO on EXAMINE for non-existent');
 my $mailbox1 = "inbox.i1.$first_range";
 ok($mic->select('inbox.i1'), 'SELECT on parent succeeds');
+ok($mic->noop, 'NOOP while selected');
+ok($mic->noop, 'NOOP again while selected'); # check warnings later
 ok($mic->select($mailbox1), 'SELECT succeeds');
 ok($mic->examine($mailbox1), 'EXAMINE succeeds');
 my @raw = $mic->status($mailbox1, qw(Messages uidnext uidvalidity));

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/5] wwwatomstream: avoid uninitialized warnings for $email
  2020-07-07 20:37 [PATCH 0/5] uninitialized vs blank fixes Eric Wong
                   ` (3 preceding siblings ...)
  2020-07-07 20:37 ` [PATCH 4/5] imap: avoid warnings on non-slice mailboxes Eric Wong
@ 2020-07-07 20:37 ` Eric Wong
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2020-07-07 20:37 UTC (permalink / raw)
  To: meta

As in Import, we'll fall back to Sender: if From: is missing,
and use the primary_address of the inboxes to indicate the total
absence of those fields.
---
 lib/PublicInbox/WwwAtomStream.pm | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/lib/PublicInbox/WwwAtomStream.pm b/lib/PublicInbox/WwwAtomStream.pm
index 3b5b133a5..2f9b953b2 100644
--- a/lib/PublicInbox/WwwAtomStream.pm
+++ b/lib/PublicInbox/WwwAtomStream.pm
@@ -136,16 +136,13 @@ sub feed_entry {
 	$title = '(no subject)' unless defined $title && $title ne '';
 	$title = title_tag($title);
 
-	my $from = $hdr->header('From') or return;
+	my $from = $hdr->header('From') // $hdr->header('Sender') //
+		$ctx->{-inbox}->{-primary_address};
 	my ($email) = PublicInbox::Address::emails($from);
-	my $name = join(', ',PublicInbox::Address::names($from));
-	$name = ascii_html($name);
-	$email = ascii_html($email);
+	my $name = ascii_html(join(', ', PublicInbox::Address::names($from)));
+	$email = ascii_html($email // $ctx->{-inbox}->{-primary_address});
 
-	my $s = '';
-	if (delete $ctx->{emit_header}) {
-		$s .= atom_header($ctx, $title);
-	}
+	my $s = delete($ctx->{emit_header}) ? atom_header($ctx, $title) : '';
 	$s .= "<entry><author><name>$name</name><email>$email</email>" .
 		"</author>$title$updated" .
 		qq(<link\nhref="$href"/>).

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-07-07 20:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-07 20:37 [PATCH 0/5] uninitialized vs blank fixes Eric Wong
2020-07-07 20:37 ` [PATCH 1/5] viewvcs: allow "0" as a path name Eric Wong
2020-07-07 20:37 ` [PATCH 2/5] hval: to_filename: return `undef' instead of empty string Eric Wong
2020-07-07 20:37 ` [PATCH 3/5] viewvcs: stop checking unused "B" query parameter Eric Wong
2020-07-07 20:37 ` [PATCH 4/5] imap: avoid warnings on non-slice mailboxes Eric Wong
2020-07-07 20:37 ` [PATCH 5/5] wwwatomstream: avoid uninitialized warnings for $email Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).