line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JMAP::Validation::Checks::String; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
6857
|
use DateTime; |
|
10
|
|
|
|
|
718725
|
|
|
10
|
|
|
|
|
302
|
|
4
|
10
|
|
|
10
|
|
382
|
use JMAP::Validation; |
|
10
|
|
|
|
|
14
|
|
|
10
|
|
|
|
|
171
|
|
5
|
10
|
|
|
10
|
|
3309
|
use JMAP::Validation::Tests::String; |
|
10
|
|
|
|
|
16
|
|
|
10
|
|
|
|
|
246
|
|
6
|
10
|
|
|
10
|
|
46
|
use Test2::Bundle::Extended; |
|
10
|
|
|
|
|
11
|
|
|
10
|
|
|
|
|
72
|
|
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 = in_set($is_string, U()); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $has_at_least_one_character = check_set( |
23
|
|
|
|
|
|
|
$is_string, |
24
|
|
|
|
|
|
|
validator(sub { |
25
|
|
|
|
|
|
|
my (%params) = @_; |
26
|
|
|
|
|
|
|
return $params{got} =~ /./; |
27
|
|
|
|
|
|
|
}), |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our $has_at_most_256_bytes = check_set( |
31
|
|
|
|
|
|
|
$is_string, |
32
|
|
|
|
|
|
|
validator(sub { |
33
|
|
|
|
|
|
|
my (%params) = @_; |
34
|
|
|
|
|
|
|
return $params{got} !~ /\C{257}/; |
35
|
|
|
|
|
|
|
}), |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
our $has_no_leading_hash = check_set( |
39
|
|
|
|
|
|
|
$is_string, |
40
|
|
|
|
|
|
|
validator(sub { |
41
|
|
|
|
|
|
|
my (%params) = @_; |
42
|
|
|
|
|
|
|
return $params{got} !~ /^#/; |
43
|
|
|
|
|
|
|
}), |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
our $is_id = check_set( |
47
|
|
|
|
|
|
|
$is_string, |
48
|
|
|
|
|
|
|
$has_at_least_one_character, |
49
|
|
|
|
|
|
|
$has_at_most_256_bytes, |
50
|
|
|
|
|
|
|
$has_no_leading_hash, |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
our $is_array_of_ids = array { |
54
|
|
|
|
|
|
|
filter_items { grep { ! JMAP::Validation::Tests::String::is_id($_) } @_ }; |
55
|
|
|
|
|
|
|
end(); |
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
our $is_date = validator(sub{ |
59
|
|
|
|
|
|
|
my (%params) = @_; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
return unless JMAP::Validation::Tests::String::is_string($params{got}); |
62
|
|
|
|
|
|
|
return unless $params{got} =~ m{^(\d\d\d\d)-(\d\d)-(\d\d)$}; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
return unless eval { |
65
|
|
|
|
|
|
|
DateTime->new( |
66
|
|
|
|
|
|
|
year => $1, |
67
|
|
|
|
|
|
|
month => $2, |
68
|
|
|
|
|
|
|
day => $3, |
69
|
|
|
|
|
|
|
) |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return 1; |
73
|
|
|
|
|
|
|
}); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
our $is_datetime = validator(sub{ |
76
|
|
|
|
|
|
|
my (%params) = @_; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
return unless JMAP::Validation::Tests::String::is_string($params{got}); |
79
|
|
|
|
|
|
|
return unless $params{got} =~ m{^(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z$}; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
return unless eval { |
82
|
|
|
|
|
|
|
DateTime->new( |
83
|
|
|
|
|
|
|
year => $1, |
84
|
|
|
|
|
|
|
month => $2, |
85
|
|
|
|
|
|
|
day => $3, |
86
|
|
|
|
|
|
|
hour => $4, |
87
|
|
|
|
|
|
|
minute => $5, |
88
|
|
|
|
|
|
|
second => $6, |
89
|
|
|
|
|
|
|
) |
90
|
|
|
|
|
|
|
}; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
return 1; |
93
|
|
|
|
|
|
|
}); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
our $is_datetime_local = validator(sub{ |
96
|
|
|
|
|
|
|
my (%params) = @_; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
return unless JMAP::Validation::Tests::String::is_string($params{got}); |
99
|
|
|
|
|
|
|
return unless $params{got} =~ m{^(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)$}; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
return unless eval { |
102
|
|
|
|
|
|
|
DateTime->new( |
103
|
|
|
|
|
|
|
year => $1, |
104
|
|
|
|
|
|
|
month => $2, |
105
|
|
|
|
|
|
|
day => $3, |
106
|
|
|
|
|
|
|
hour => $4, |
107
|
|
|
|
|
|
|
minute => $5, |
108
|
|
|
|
|
|
|
second => $6, |
109
|
|
|
|
|
|
|
) |
110
|
|
|
|
|
|
|
}; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
return 1; |
113
|
|
|
|
|
|
|
}); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# }}} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |