X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FSolverGit.pm;h=c32a5baecdbc2a6366c64bb3ad79400e9eacdb34;hb=87678710135973f72722258e171fc00f85c86ec8;hp=bf806f65661a5d6637ef89401f34104d25c7ffde;hpb=ea30a1fcab1823062e5375f2670dadc80c712f74;p=public-inbox.git
diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm
index bf806f65..c32a5bae 100644
--- a/lib/PublicInbox/SolverGit.pm
+++ b/lib/PublicInbox/SolverGit.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2019 all contributors
+# Copyright (C) 2019-2020 all contributors
# License: AGPL-3.0+
# "Solve" blobs which don't exist in git code repositories by
@@ -34,6 +34,12 @@ my $OID_MIN = 7;
# work fairly. Other PSGI servers may have trouble, though.
my $MAX_PATCH = 9999;
+my $LF = qr!\r?\n!;
+my $ANY = qr![^\r\n]+!;
+my $MODE = '100644|120000|100755';
+my $FN = qr!(?:("?[^/\n]+/[^\r\n]+)|/dev/null)!;
+my %BAD_COMPONENT = ('' => 1, '.' => 1, '..' => 1);
+
# di = diff info / a hashref with information about a diff ($di):
# {
# oid_a => abbreviated pre-image oid,
@@ -42,7 +48,7 @@ my $MAX_PATCH = 9999;
# hdr_lines => string of various header lines for mode information
# mode_a => original mode of oid_a (string, not integer),
# ibx => PublicInbox::Inbox object containing the diff
-# smsg => PublicInbox::SearchMsg object containing diff
+# smsg => PublicInbox::Smsg object containing diff
# path_a => pre-image path
# path_b => post-image path
# n => numeric path of the patch (relative to worktree)
@@ -110,10 +116,6 @@ sub extract_diff ($$) {
$s =~ s/\r\n/\n/sg;
}
- state $LF = qr!\r?\n!;
- state $ANY = qr![^\r\n]+!;
- state $MODE = '100644|120000|100755';
- state $FN = qr!(?:("?[^/\n]+/[^\r\n]+)|/dev/null)!;
$s =~ m!( # $1 start header lines we save for debugging:
@@ -174,8 +176,7 @@ sub extract_diff ($$) {
# get rid of path-traversal attempts and junk patches:
# it's junk at best, an attack attempt at worse:
- state $bad_component = { map { $_ => 1 } ('', '.', '..') };
- foreach (@a, @b) { return if $bad_component->{$_} }
+ foreach (@a, @b) { return if $BAD_COMPONENT{$_} }
$di->{path_a} = join('/', @a) if @a;
$di->{path_b} = join('/', @b);