user/dev discussion of public-inbox itself
 help / color / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 21/24] require ASCII digits for local FS items
Date: Tue,  4 Jun 2019 11:27:45 +0000
Message-ID: <20190604112748.23598-22-e@80x24.org> (raw)
In-Reply-To: <20190604112748.23598-1-e@80x24.org>

In case some BOFH decides to randomly create directories
using non-ASCII digits all over the place.
---
 lib/PublicInbox/Inbox.pm      | 4 ++--
 lib/PublicInbox/Search.pm     | 2 +-
 lib/PublicInbox/V2Writable.pm | 4 ++--
 lib/PublicInbox/Xapcmd.pm     | 6 +++---
 script/public-inbox-purge     | 2 +-
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index 04d2f83..c933033 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -87,7 +87,7 @@ sub _set_limiter ($$$) {
 		my $mkey = $pfx.'max';
 		my $val = $self->{$mkey} or return;
 		my $lim;
-		if ($val =~ /\A\d+\z/) {
+		if ($val =~ /\A[0-9]+\z/) {
 			require PublicInbox::Qspawn;
 			$lim = PublicInbox::Qspawn::Limiter->new($val);
 		} elsif ($val =~ /\A[a-z][a-z0-9]*\z/) {
@@ -161,7 +161,7 @@ sub max_git_part {
 		if (opendir my $dh, $gits) {
 			my $max = -1;
 			while (defined(my $git_dir = readdir($dh))) {
-				$git_dir =~ m!\A(\d+)\.git\z! or next;
+				$git_dir =~ m!\A([0-9]+)\.git\z! or next;
 				$max = $1 if $1 > $max;
 			}
 			$part = $self->{-max_git_part} = $max if $max >= 0;
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index c054a87..9903f42 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -144,7 +144,7 @@ sub _xdb ($) {
 	my $qpf = \($self->{qp_flags} ||= $QP_FLAGS);
 	if ($self->{version} >= 2) {
 		foreach my $part (<$dir/*>) {
-			-d $part && $part =~ m!/\d+\z! or next;
+			-d $part && $part =~ m!/[0-9]+\z! or next;
 			my $sub = Search::Xapian::Database->new($part);
 			if ($xdb) {
 				$xdb->add_database($sub);
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 76844cd..a8c33ef 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -48,7 +48,7 @@ sub count_partitions ($) {
 	# due to -compact
 	if (-d $xpfx) {
 		foreach my $part (<$xpfx/*>) {
-			-d $part && $part =~ m!/\d+\z! or next;
+			-d $part && $part =~ m!/[0-9]+\z! or next;
 			eval {
 				Search::Xapian::Database->new($part)->close;
 				$nparts++;
@@ -574,7 +574,7 @@ sub git_dir_latest {
 	my $latest;
 	opendir my $dh, $pfx or die "opendir $pfx: $!\n";
 	while (defined(my $git_dir = readdir($dh))) {
-		$git_dir =~ m!\A(\d+)\.git\z! or next;
+		$git_dir =~ m!\A([0-9]+)\.git\z! or next;
 		if ($1 > $$max) {
 			$$max = $1;
 			$latest = "$pfx/$git_dir";
diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm
index 9067231..dad080c 100644
--- a/lib/PublicInbox/Xapcmd.pm
+++ b/lib/PublicInbox/Xapcmd.pm
@@ -150,7 +150,7 @@ sub run {
 	} else {
 		opendir my $dh, $old or die "Failed to opendir $old: $!\n";
 		while (defined(my $dn = readdir($dh))) {
-			if ($dn =~ /\A\d+\z/) {
+			if ($dn =~ /\A[0-9]+\z/) {
 				my $tmpl = "$dn-XXXXXXXX";
 				my $dst = tempdir($tmpl, DIR => $old);
 				same_fs_or_die($old, $dst);
@@ -200,7 +200,7 @@ sub progress_pfx ($) {
 	my @p = split('/', $_[0]);
 
 	# return "xap15/0" for v2, or "xapian15" for v1:
-	($p[-1] =~ /\A\d+\z/) ? "$p[-2]/$p[-1]" : $p[-1];
+	($p[-1] =~ /\A[0-9]+\z/) ? "$p[-2]/$p[-1]" : $p[-1];
 }
 
 # xapian-compact wrapper
@@ -276,7 +276,7 @@ sub cpdb ($$) {
 			$dst->set_metadata('last_commit', $lc) if $lc;
 
 			# only the first xapian partition (0) gets 'indexlevel'
-			if ($old =~ m!(?:xapian\d+|xap\d+/0)\z!) {
+			if ($old =~ m!(?:xapian[0-9]+|xap[0-9]+/0)\z!) {
 				my $l = $src->get_metadata('indexlevel');
 				if ($l eq 'medium') {
 					$dst->set_metadata('indexlevel', $l);
diff --git a/script/public-inbox-purge b/script/public-inbox-purge
index 381826d..25e6cc9 100755
--- a/script/public-inbox-purge
+++ b/script/public-inbox-purge
@@ -91,7 +91,7 @@ foreach my $ibx (@inboxes) {
 	my $xdir_ro = $ibx->{search}->xdir(1);
 	my $npart = 0;
 	foreach my $part (<$xdir_ro/*>) {
-		if (-d $part && $part =~ m!/\d+\z!) {
+		if (-d $part && $part =~ m!/[0-9]+\z!) {
 			my $bytes = 0;
 			$bytes += -s $_ foreach glob("$part/*");
 			$npart++ if $bytes;
-- 
EW


  parent reply index

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-04 11:27 [PATCH 00/24] fix IDN linkification, add paranoia Eric Wong
2019-06-04 11:27 ` [PATCH 01/24] linkify: support Internationalized Domain Names in URLs Eric Wong
2019-06-04 11:27 ` [PATCH 02/24] nntp: be explicit about ASCII digit matches Eric Wong
2019-06-04 11:27 ` [PATCH 03/24] nntp: ensure we only handle ASCII whitespace Eric Wong
2019-06-04 11:27 ` [PATCH 04/24] mid: id_compress requires ASCII-clean words Eric Wong
2019-06-04 11:27 ` [PATCH 05/24] feed: only accept ASCII digits for ref~$N Eric Wong
2019-06-04 11:27 ` [PATCH 06/24] http: require SERVER_PORT to be ASCII digit Eric Wong
2019-06-04 11:27 ` [PATCH 07/24] wwwlisting: require ASCII digit for port number Eric Wong
2019-06-04 11:27 ` [PATCH 08/24] wwwattach: only pass the charset through if ASCII Eric Wong
2019-06-04 11:27 ` [PATCH 09/24] www: only emit ASCII chars in attachment filenames Eric Wong
2019-06-04 11:27 ` [PATCH 10/24] www: require ASCII filenames in git blob downloads Eric Wong
2019-06-04 11:27 ` [PATCH 11/24] config: do not accept non-ASCII digits in cgitrc params Eric Wong
2019-06-04 11:27 ` [PATCH 12/24] newswww: only accept ASCII digits as article numbers Eric Wong
2019-06-04 11:27 ` [PATCH 13/24] view: require YYYYmmDD(HHMMSS) timestamps to be ASCII Eric Wong
2019-06-04 11:27 ` [PATCH 14/24] githttpbackend: require Range:, Status: to be ASCII digits Eric Wong
2019-06-04 11:27 ` [PATCH 15/24] searchview: do not allow non-ASCII offsets and limits Eric Wong
2019-06-04 11:27 ` [PATCH 16/24] msgtime: require ASCII digits for parsing dates Eric Wong
2019-06-04 11:27 ` [PATCH 17/24] filter/rubylang: require ASCII digit for mailcount Eric Wong
2019-06-04 11:27 ` [PATCH 18/24] inbox: require ASCII digits for feedmax var Eric Wong
2019-06-04 11:27 ` [PATCH 19/24] solver|viewdiff: restrict digit matches to ASCII Eric Wong
2019-06-04 11:27 ` [PATCH 20/24] www: require ASCII digit for git epoch Eric Wong
2019-06-04 11:27 ` Eric Wong [this message]
2019-06-04 11:27 ` [PATCH 22/24] githttpbackend: require ASCII in path Eric Wong
2019-06-04 11:27 ` [PATCH 23/24] www: require ASCII range for mbox downloads Eric Wong
2019-06-04 11:27 ` [PATCH 24/24] www: require ASCII word characters for CSS filenames Eric Wong
2019-06-05  2:18 ` [PATCH 25/24] tighten up digit matches to ASCII for git output Eric Wong

Reply instructions:

You may reply publically 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=20190604112748.23598-22-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

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox