gitweb: Move check-ref-format code into separate function
This check will be used in more than one place later. Signed-off-by: Krzesimir Nowak <krzesimir@endocode.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Krzesimir Nowak committed
Dec 11, 2013 at 12:54 UTC
c0bc2265ef74331c0314be4a3f148e784800c3de
1 file changed
+13
-4
gitweb/gitweb.perl
+13
-4
@@ -1452,6 +1452,16 @@ sub validate_pathname {
1452
return $input;
1453
}
1454
1455
+sub is_valid_ref_format {
1456
+ my $input = shift || return undef;
1457
+
1458
+ # restrictions on ref name according to git-check-ref-format
1459
+ if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1460
+ return undef;
1461
+ }
1462
+ return $input;
1463
+}
1464
+
1465
sub validate_refname {
1466
my $input = shift || return undef;
1467
@@ -1462,10 +1472,9 @@ sub validate_refname {
1472
# it must be correct pathname
1473
$input = validate_pathname($input)
1474
or return undef;
1465
- # restrictions on ref name according to git-check-ref-format
1466
- if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1467
- return undef;
1468
- }
1475
+ # check git-check-ref-format restrictions
1476
+ is_valid_ref_format($input)
1477
+ or return undef;
1478
return $input;
1479
}
1480