gitweb/indextext_readonly.html: include sample readonly file
[girocco.git] / Girocco / ValidUtil.pm
blob6f285dca2469adf4e2868e91ce9d7ab6e6f80585
1 # This package contains validation checks that are use'd by
2 # both Girocco::Validator (which is an install-only module)
3 # and by Girocco::Util (which is a runtime module).
4 # It MUST NOT use any other Girocco modules!!!
5 # (And really SHOULD NOT use any other modules either.)
7 package Girocco::ValidUtil;
9 use 5.008;
10 use strict;
11 use warnings;
13 BEGIN {
14 use base qw(Exporter);
15 our @EXPORT = qw(valid_branch_name);
18 # Return undef if input argument is undef
19 # Otherwise return true if the argument is considered a valid Git branch name
20 # as far as Girocco is concerned. The "branch name" is the part AFTER the
21 # initial "refs/heads/". In other words the ref "refs/heads/master" represents
22 # the "branch name" known as "master".
23 # This function expects the bare branch name (e.g. "master") to be passed to
24 # it for validation. Note that an empty branch name (i.e. "") is not valid.
25 # Branch naming rules (mostly the rules applied by `git check-ref-format` with
26 # a few Girocco extra restrictions thrown in):
27 # 1. MUST NOT start with or end with a '/'(0x2f)
28 # 2. MAY have hierarchical components which MUST be separated with '/'(0x2f)
29 # 3. MUST NOT have any empty components (the part between two '/'s) (i.e. '//')
30 # 4. MUST NOT have any component that starts with or ends with a '.'(0x2e)
31 # 5. MUST NOT have any component that ends with '.lock' (case-insensitively)
32 # 6. MUST NOT contain any characters with a value between 0x00 and 0x1f (inclusive)
33 # 7. MUST NOT contain any space (0x20), backslash (0x5c) or DEL (0x7f) characters
34 # 8. MUST NOT contain any globbing characters '?'(0x3f), '*'(0x2a), '['(0x5b)
35 # 9. MUST NOT contain any Git-special characters '~'(0x7e), '^'(0x5e), ':'(0x3a)
36 # 10. MUST NOT contain the Git-special sequence '..'(0x2e 0x2e)
37 # 11. MUST NOT contain the Git-special sequence '@{'(0x40 0x7b)
38 # 12. MUST NOT be the Git-special branch name '@'(0x40)
39 # 13. MUST NOT contain (Girocco-disallowed) any quote characters "'"(0x27) or '"'(0x22)
40 # 14. MUST NOT contain (Girocco-disallowed) any '<'(0x3c) or '>'(0x3e) characters
41 sub valid_branch_name {
42 my $b = shift;
43 defined $b or return undef;
44 $b ne "" or return "";
45 return $b !~ m{
46 ^/ | /$ | # rule 1
47 // | # rules 2+3
48 (?:^|/)[.] | [.](?:/|$) | # rule 4
49 [.][lL][oO][cC][kK](?:/|$) | # rule 5
50 [\x00-\x1f "'"*:<>?\[\\^~\x7f] | # rules 6+7+8+9+13+14
51 [.][.] | [\@][\{] | # rules 10+11
52 ^\@$ # rule 12
53 }xo;