line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JMAP::Validation::Checks::String; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
7003
|
use DateTime; |
|
10
|
|
|
|
|
734027
|
|
|
10
|
|
|
|
|
332
|
|
4
|
10
|
|
|
10
|
|
371
|
use JMAP::Validation; |
|
10
|
|
|
|
|
13
|
|
|
10
|
|
|
|
|
179
|
|
5
|
10
|
|
|
10
|
|
3225
|
use JMAP::Validation::Tests::String; |
|
10
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
218
|
|
6
|
10
|
|
|
10
|
|
40
|
use Test2::Bundle::Extended; |
|
10
|
|
|
|
|
10
|
|
|
10
|
|
|
|
|
69
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# data types {{{ |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $is_string = validator(sub { |
11
|
|
|
|
|
|
|
my (%params) = @_; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
return (ref($params{got}) || '') eq 'JSON::Typist::String'; |
14
|
|
|
|
|
|
|
}); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# }}} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# restrictions {{{ |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $is_string_or_null = validator(sub { |
21
|
|
|
|
|
|
|
my (%params) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
if (defined $params{got}) { |
24
|
|
|
|
|
|
|
return unless JMAP::Validation::validate( |
25
|
|
|
|
|
|
|
$params{got}, |
26
|
|
|
|
|
|
|
$is_string, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
return 1; |
31
|
|
|
|
|
|
|
}); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our $has_at_least_one_character = check_set( |
34
|
|
|
|
|
|
|
$is_string, |
35
|
|
|
|
|
|
|
validator(sub { |
36
|
|
|
|
|
|
|
my (%params) = @_; |
37
|
|
|
|
|
|
|
return $params{got} =~ /./; |
38
|
|
|
|
|
|
|
}), |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
our $has_at_most_256_bytes = check_set( |
42
|
|
|
|
|
|
|
$is_string, |
43
|
|
|
|
|
|
|
validator(sub { |
44
|
|
|
|
|
|
|
my (%params) = @_; |
45
|
|
|
|
|
|
|
return $params{got} !~ /\C{257}/; |
46
|
|
|
|
|
|
|
}), |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
our $has_no_leading_hash = check_set( |
50
|
|
|
|
|
|
|
$is_string, |
51
|
|
|
|
|
|
|
validator(sub { |
52
|
|
|
|
|
|
|
my (%params) = @_; |
53
|
|
|
|
|
|
|
return $params{got} !~ /^#/; |
54
|
|
|
|
|
|
|
}), |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
our $is_id = check_set( |
58
|
|
|
|
|
|
|
$is_string, |
59
|
|
|
|
|
|
|
$has_at_least_one_character, |
60
|
|
|
|
|
|
|
$has_at_most_256_bytes, |
61
|
|
|
|
|
|
|
$has_no_leading_hash, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
our $is_array_of_ids = array { |
65
|
|
|
|
|
|
|
filter_items { grep { ! JMAP::Validation::Tests::String::is_id($_) } @_ }; |
66
|
|
|
|
|
|
|
end(); |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
our $is_date = validator(sub{ |
70
|
|
|
|
|
|
|
my (%params) = @_; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return unless JMAP::Validation::Tests::String::is_string($params{got}); |
73
|
|
|
|
|
|
|
return unless $params{got} =~ m{^(\d\d\d\d)-(\d\d)-(\d\d)$}; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return unless eval { |
76
|
|
|
|
|
|
|
DateTime->new( |
77
|
|
|
|
|
|
|
year => $1, |
78
|
|
|
|
|
|
|
month => $2, |
79
|
|
|
|
|
|
|
day => $3, |
80
|
|
|
|
|
|
|
) |
81
|
|
|
|
|
|
|
}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
return 1; |
84
|
|
|
|
|
|
|
}); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# }}} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |