about summary refs log tree commit homepage
path: root/lib/PublicInbox/Config.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-01-01 10:18:47 +0000
committerEric Wong <e@80x24.org>2019-01-02 08:33:37 +0000
commitbf7315de01fecc74ff8807921a993145886a8007 (patch)
tree6cc44f3885ea00159b5d67f8fdf8dd330dba2dc6 /lib/PublicInbox/Config.pm
parentbd06b22c9fa498d72808cebfa3987718288ce5db (diff)
downloadpublic-inbox-bf7315de01fecc74ff8807921a993145886a8007.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/Config.pm')
-rw-r--r--lib/PublicInbox/Config.pm13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 78586560..a2b721d2 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);