* Re: [PATCH] wwwlisting: fix grep call for match=domain filtering
2020-07-30 5:30 5% [PATCH] wwwlisting: fix grep call for match=domain filtering Kyle Meyer
@ 2020-07-30 8:03 0% ` Eric Wong
0 siblings, 0 replies; 6+ results
From: Eric Wong @ 2020-07-30 8:03 UTC (permalink / raw)
To: Kyle Meyer; +Cc: meta
Kyle Meyer <kyle@kyleam.com> wrote:
> The grep call in list_match_domain_i returns true for all inboxes,
> even ones without a URL that matches the regular expression, because
> the qr value passed to grep is not surrounded by slashes. Add them.
>
> Fixes: 1988d730c0088e8b (config: support multi-value inbox.*.*url)
Thanks, pushed as commit 41ecd08ee60daa495de3a2fc2c0296dc9cc9a0b3
> sub list_match_domain_i {
> my ($ibx, $arg) = @_;
> my ($list, $hide_key, $re) = @$arg;
> - if (!$ibx->{-hide}->{$hide_key} && grep($re, @{$ibx->{url}})) {
> + if (!$ibx->{-hide}->{$hide_key} && grep(/$re/, @{$ibx->{url}})) {
Gah, I keep getting languages/behaviors confused :x
Especially confusing since `$string =~ $re' is documented
in perlop(1) as being equivalent to `$string =~ /$re/'
^ permalink raw reply [relevance 0%]
* [PATCH] wwwlisting: fix grep call for match=domain filtering
@ 2020-07-30 5:30 5% Kyle Meyer
2020-07-30 8:03 0% ` Eric Wong
0 siblings, 1 reply; 6+ results
From: Kyle Meyer @ 2020-07-30 5:30 UTC (permalink / raw)
To: meta
The grep call in list_match_domain_i returns true for all inboxes,
even ones without a URL that matches the regular expression, because
the qr value passed to grep is not surrounded by slashes. Add them.
Fixes: 1988d730c0088e8b (config: support multi-value inbox.*.*url)
---
lib/PublicInbox/WwwListing.pm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/PublicInbox/WwwListing.pm b/lib/PublicInbox/WwwListing.pm
index 5f85e346..0af0fe68 100644
--- a/lib/PublicInbox/WwwListing.pm
+++ b/lib/PublicInbox/WwwListing.pm
@@ -40,7 +40,7 @@ sub list_all ($$$) {
sub list_match_domain_i {
my ($ibx, $arg) = @_;
my ($list, $hide_key, $re) = @$arg;
- if (!$ibx->{-hide}->{$hide_key} && grep($re, @{$ibx->{url}})) {
+ if (!$ibx->{-hide}->{$hide_key} && grep(/$re/, @{$ibx->{url}})) {
push @$list, $ibx;
}
}
base-commit: 9e0c2886493863b4bc6483ce0a3bfd3d599c8c87
--
2.27.0
^ permalink raw reply related [relevance 5%]
* [PATCH 1/4] wwwtext: show multiple infourl values properly
@ 2020-02-01 9:12 5% ` Eric Wong
0 siblings, 0 replies; 6+ results
From: Eric Wong @ 2020-02-01 9:12 UTC (permalink / raw)
To: meta
This is now an array, so ensure it's shown properly in the
sample config, instead of "ARRAY(0xI8BADBEEF)" or similar.
Fixes: 1988d730c0088e8b "config: support multi-value inbox.*.*url"
---
lib/PublicInbox/WwwText.pm | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm
index 2e4aeec0..ace7f9d7 100644
--- a/lib/PublicInbox/WwwText.pm
+++ b/lib/PublicInbox/WwwText.pm
@@ -148,12 +148,12 @@ sub inbox_config ($$$) {
; instead of "inboxdir", both remain supported after 1.2
mainrepo = /path/to/top-level-inbox
EOS
- for my $k (qw(address listid)) {
+ for my $k (qw(address listid infourl)) {
defined(my $v = $ibx->{$k}) or next;
$$txt .= "\t$k = $_\n" for @$v;
}
- for my $k (qw(filter infourl newsgroup obfuscate replyto watchheader)) {
+ for my $k (qw(filter newsgroup obfuscate replyto watchheader)) {
defined(my $v = $ibx->{$k}) or next;
$$txt .= "\t$k = $v\n";
}
^ permalink raw reply related [relevance 5%]
* Re: [PATCH 2/2] config: support multi-value inbox.*.*url
2020-01-02 3:09 5% ` [PATCH 2/2] config: support multi-value inbox.*.*url Eric Wong
@ 2020-01-02 20:56 7% ` Eric Wong
0 siblings, 0 replies; 6+ results
From: Eric Wong @ 2020-01-02 20:56 UTC (permalink / raw)
To: meta
Eric Wong <e@80x24.org> wrote:
> +++ b/lib/PublicInbox/Hval.pm
> @@ -86,6 +86,13 @@ sub raw {
>
> sub prurl {
> my ($env, $u) = @_;
> + if (ref($u) eq 'ARRAY') {
> + my $h = $env->{HTTP_HOST} // $env->{SERVER_NAME};
> + if (my @host_match = grep(/\b\Q$h\E\b/, @$u)) {
> + return prurl($env, $host_match[0]);
> + }
> + $u = $u->[0]; # fall through to below:
> + }
> index($u, '//') == 0 ? "$env->{'psgi.url_scheme'}:$u" : $u;
> }
No need for recursion, actually :x
diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm
index 0a0de834..cd3a4df3 100644
--- a/lib/PublicInbox/Hval.pm
+++ b/lib/PublicInbox/Hval.pm
@@ -88,10 +88,9 @@ sub prurl {
my ($env, $u) = @_;
if (ref($u) eq 'ARRAY') {
my $h = $env->{HTTP_HOST} // $env->{SERVER_NAME};
- if (my @host_match = grep(/\b\Q$h\E\b/, @$u)) {
- return prurl($env, $host_match[0]);
- }
- $u = $u->[0]; # fall through to below:
+ my @host_match = grep(/\b\Q$h\E\b/, @$u);
+ $u = $host_match[0] // $u->[0];
+ # fall through to below:
}
index($u, '//') == 0 ? "$env->{'psgi.url_scheme'}:$u" : $u;
}
^ permalink raw reply related [relevance 7%]
* [PATCH 0/2] support multiple "url" and "infourl" values
@ 2020-01-02 3:09 5% Eric Wong
2020-01-02 3:09 5% ` [PATCH 2/2] config: support multi-value inbox.*.*url Eric Wong
0 siblings, 1 reply; 6+ results
From: Eric Wong @ 2020-01-02 3:09 UTC (permalink / raw)
To: meta
This should make migrating inboxes to new domains easier,
since ICANN has proven they cannot be trusted after the
.org situation.
Eric Wong (2):
wwwlisting: show configured "infourl" properly
config: support multi-value inbox.*.*url
lib/PublicInbox/Config.pm | 7 ++++---
lib/PublicInbox/Hval.pm | 7 +++++++
lib/PublicInbox/Inbox.pm | 2 +-
lib/PublicInbox/WwwListing.pm | 6 +++---
t/config.t | 4 ++--
t/feed.t | 2 +-
t/inbox.t | 4 ++--
t/nntp.t | 2 +-
8 files changed, 21 insertions(+), 13 deletions(-)
^ permalink raw reply [relevance 5%]
* [PATCH 2/2] config: support multi-value inbox.*.*url
2020-01-02 3:09 5% [PATCH 0/2] support multiple "url" and "infourl" values Eric Wong
@ 2020-01-02 3:09 5% ` Eric Wong
2020-01-02 20:56 7% ` Eric Wong
0 siblings, 1 reply; 6+ results
From: Eric Wong @ 2020-01-02 3:09 UTC (permalink / raw)
To: meta
Since the beginning of this project, we've implicitly supported
inboxes with multiple URLs by relying on the Host: header sent
by the client ($env->{HTTP_HOST}).
We now offer the option to explicitly configure multiple URLs for
every inbox along with the ability to do a best-effort match for
matching hostnames.
---
lib/PublicInbox/Config.pm | 7 ++++---
lib/PublicInbox/Hval.pm | 7 +++++++
lib/PublicInbox/Inbox.pm | 2 +-
lib/PublicInbox/WwwListing.pm | 4 ++--
t/config.t | 4 ++--
t/feed.t | 2 +-
t/inbox.t | 4 ++--
t/nntp.t | 2 +-
8 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 8ecf549d..ffc31f83 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -362,8 +362,8 @@ sub _fill {
my ($self, $pfx) = @_;
my $ibx = {};
- foreach my $k (qw(inboxdir filter url newsgroup
- infourl watch watchheader httpbackendmax
+ foreach my $k (qw(inboxdir filter newsgroup
+ watch watchheader httpbackendmax
replyto feedmax nntpserver indexlevel)) {
my $v = $self->{"$pfx.$k"};
$ibx->{$k} = $v if defined $v;
@@ -383,7 +383,8 @@ sub _fill {
}
# TODO: more arrays, we should support multi-value for
# more things to encourage decentralization
- foreach my $k (qw(address altid nntpmirror coderepo hide listid)) {
+ foreach my $k (qw(address altid nntpmirror coderepo hide listid url
+ infourl)) {
if (defined(my $v = $self->{"$pfx.$k"})) {
$ibx->{$k} = _array($v);
}
diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm
index 4a79439f..0a0de834 100644
--- a/lib/PublicInbox/Hval.pm
+++ b/lib/PublicInbox/Hval.pm
@@ -86,6 +86,13 @@ sub raw {
sub prurl {
my ($env, $u) = @_;
+ if (ref($u) eq 'ARRAY') {
+ my $h = $env->{HTTP_HOST} // $env->{SERVER_NAME};
+ if (my @host_match = grep(/\b\Q$h\E\b/, @$u)) {
+ return prurl($env, $host_match[0]);
+ }
+ $u = $u->[0]; # fall through to below:
+ }
index($u, '//') == 0 ? "$env->{'psgi.url_scheme'}:$u" : $u;
}
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index f294c0d5..a3cdcbc0 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -252,7 +252,7 @@ sub base_url {
} else {
# either called from a non-PSGI environment (e.g. NNTP/POP3)
$self->{-base_url} ||= do {
- my $url = $self->{url} or return undef;
+ my $url = $self->{url}->[0] or return undef;
# expand protocol-relative URLs to HTTPS if we're
# not inside a web server
$url = "https:$url" if $url =~ m!\A//!;
diff --git a/lib/PublicInbox/WwwListing.pm b/lib/PublicInbox/WwwListing.pm
index 1faade6c..4f076b7d 100644
--- a/lib/PublicInbox/WwwListing.pm
+++ b/lib/PublicInbox/WwwListing.pm
@@ -32,7 +32,7 @@ sub list_all ($$$) {
sub list_match_domain_i {
my ($ibx, $arg) = @_;
my ($list, $hide_key, $re) = @$arg;
- if (!$ibx->{-hide}->{$hide_key} && $ibx->{url} =~ $re) {
+ if (!$ibx->{-hide}->{$hide_key} && grep($re, @{$ibx->{url}})) {
push @$list, $ibx;
}
}
@@ -90,7 +90,7 @@ sub ibx_entry {
${\$ibx->description}
if (defined(my $info_url = $ibx->{infourl})) {
- $tmp .= ' ' . $info_url . "\n";
+ $tmp .= ' ' . PublicInbox::Hval::prurl($env, $info_url) . "\n";
}
$tmp;
}
diff --git a/t/config.t b/t/config.t
index db3f9b2a..1ec864b4 100644
--- a/t/config.t
+++ b/t/config.t
@@ -27,7 +27,7 @@ my ($tmpdir, $for_destroy) = tmpdir();
'inboxdir' => '/home/pi/meta-main.git',
'address' => [ 'meta@public-inbox.org' ],
'domain' => 'public-inbox.org',
- 'url' => 'http://example.com/meta',
+ 'url' => [ 'http://example.com/meta' ],
-primary_address => 'meta@public-inbox.org',
'name' => 'meta',
feedmax => 25,
@@ -48,7 +48,7 @@ my ($tmpdir, $for_destroy) = tmpdir();
'domain' => 'public-inbox.org',
'name' => 'test',
feedmax => 25,
- 'url' => 'http://example.com/test',
+ 'url' => [ 'http://example.com/test' ],
-httpbackend_limiter => undef,
nntpserver => undef,
}, "lookup matches expected output for test");
diff --git a/t/feed.t b/t/feed.t
index 97468c73..b2a94487 100644
--- a/t/feed.t
+++ b/t/feed.t
@@ -29,7 +29,7 @@ my $ibx = PublicInbox::Inbox->new({
address => 'test@example',
name => 'testbox',
inboxdir => $git_dir,
- url => 'http://example.com/test',
+ url => [ 'http://example.com/test' ],
feedmax => 3,
});
my $git = $ibx->git;
diff --git a/t/inbox.t b/t/inbox.t
index c9674290..a466dd13 100644
--- a/t/inbox.t
+++ b/t/inbox.t
@@ -4,9 +4,9 @@ use strict;
use warnings;
use Test::More;
use_ok 'PublicInbox::Inbox';
-my $x = PublicInbox::Inbox->new({url => '//example.com/test/'});
+my $x = PublicInbox::Inbox->new({url => [ '//example.com/test/' ]});
is($x->base_url, 'https://example.com/test/', 'expanded protocol-relative');
-$x = PublicInbox::Inbox->new({url => 'http://example.com/test'});
+$x = PublicInbox::Inbox->new({url => [ 'http://example.com/test' ]});
is($x->base_url, 'http://example.com/test/', 'added trailing slash');
$x = PublicInbox::Inbox->new({});
diff --git a/t/nntp.t b/t/nntp.t
index 961b3d6a..938eef38 100644
--- a/t/nntp.t
+++ b/t/nntp.t
@@ -104,7 +104,7 @@ use_ok 'PublicInbox::Inbox';
-primary_address => 'a@example.com',
newsgroup => 'test',
domain => 'example.com',
- url => '//example.com/a'});
+ url => [ '//example.com/a' ]});
is($ng->base_url, $u, 'URL expanded');
my $mid = 'a@b';
my $mime = Email::MIME->new("Message-ID: <$mid>\r\n\r\n");
^ permalink raw reply related [relevance 5%]
Results 1-6 of 6 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2020-01-02 3:09 5% [PATCH 0/2] support multiple "url" and "infourl" values Eric Wong
2020-01-02 3:09 5% ` [PATCH 2/2] config: support multi-value inbox.*.*url Eric Wong
2020-01-02 20:56 7% ` Eric Wong
2020-02-01 9:12 [PATCH 0/4] flesh out multi-URL support Eric Wong
2020-02-01 9:12 5% ` [PATCH 1/4] wwwtext: show multiple infourl values properly Eric Wong
2020-07-30 5:30 5% [PATCH] wwwlisting: fix grep call for match=domain filtering Kyle Meyer
2020-07-30 8:03 0% ` 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).