user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/2] config: relax name inbox name restrictions
Date: Tue,  1 Jan 2019 10:18:47 +0000	[thread overview]
Message-ID: <20190101101847.22805-3-e@80x24.org> (raw)
In-Reply-To: <20190101101847.22805-1-e@80x24.org>

Since "publicinbox" sections are analogous to git remotes, we
may use the same rules for naming git remotes to reduce
cognitive overhead.

Most notably, this allows '.' in the middle of inbox names,
(e.g. "foo.bar") as it's common for email addresses, too.
---
 lib/PublicInbox/Config.pm | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 7858656..a2b721d 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -54,7 +54,7 @@ sub lookup {
 	my $pfx;
 
 	foreach my $k (keys %$self) {
-		$k =~ /\A(publicinbox\.[\w-]+)\.address\z/ or next;
+		$k =~ m!\A(publicinbox\.[^/]+)\.address\z! or next;
 		my $v = $self->{$k};
 		if (ref($v) eq "ARRAY") {
 			foreach my $alias (@$v) {
@@ -81,7 +81,7 @@ sub each_inbox {
 	my ($self, $cb) = @_;
 	my %seen;
 	foreach my $k (keys %$self) {
-		$k =~ /\Apublicinbox\.([A-Z0-9a-z-]+)\.mainrepo\z/ or next;
+		$k =~ m!\Apublicinbox\.([^/]+)\.mainrepo\z! or next;
 		next if $seen{$1};
 		$seen{$1} = 1;
 		my $ibx = lookup_name($self, $1) or next;
@@ -96,7 +96,7 @@ sub lookup_newsgroup {
 	return $rv if $rv;
 
 	foreach my $k (keys %$self) {
-		$k =~ /\A(publicinbox\.[\w-]+)\.newsgroup\z/ or next;
+		$k =~ m!\A(publicinbox\.[^/]+)\.newsgroup\z! or next;
 		my $v = $self->{$k};
 		my $pfx = $1;
 		if ($v eq $ng) {
@@ -184,6 +184,13 @@ sub _fill {
 	return unless $rv->{mainrepo};
 	my $name = $pfx;
 	$name =~ s/\Apublicinbox\.//;
+
+	# same rules as git.git/remote.c::valid_remote_nick
+	if ($name eq '' || $name =~ m!/! || $name eq '.' || $name eq '..') {
+		warn "invalid inbox name: '$name'\n";
+		return;
+	}
+
 	$rv->{name} = $name;
 	$rv->{-pi_config} = $self;
 	$rv = PublicInbox::Inbox->new($rv);
-- 
EW


      parent reply	other threads:[~2019-01-01 10:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-01 10:18 [PATCH 0/2] config-related cleanups Eric Wong
2019-01-01 10:18 ` [PATCH 1/2] use PublicInbox::Config::each_inbox where appropriate Eric Wong
2019-01-01 10:18 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190101101847.22805-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).