This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace ValueParsers\Test; |
||
4 | |||
5 | use DataValues\TimeValue; |
||
6 | use ValueParsers\IsoTimestampParser; |
||
7 | use ValueParsers\MonthNameUnlocalizer; |
||
8 | use ValueParsers\ParserOptions; |
||
9 | use ValueParsers\PhpDateTimeParser; |
||
10 | use ValueParsers\ValueParser; |
||
11 | |||
12 | /** |
||
13 | * @covers ValueParsers\PhpDateTimeParser |
||
14 | * |
||
15 | * @group DataValue |
||
16 | * @group DataValueExtensions |
||
17 | * @group TimeParsers |
||
18 | * @group ValueParsers |
||
19 | * |
||
20 | * @license GPL-2.0-or-later |
||
21 | * @author Addshore |
||
22 | * @author Thiemo Kreuz |
||
23 | */ |
||
24 | class PhpDateTimeParserTest extends ValueParserTestCase { |
||
25 | |||
26 | /** |
||
27 | * @see ValueParserTestBase::getInstance |
||
28 | * |
||
29 | * @return PhpDateTimeParser |
||
30 | */ |
||
31 | protected function getInstance() { |
||
32 | $options = new ParserOptions(); |
||
33 | |||
34 | return new PhpDateTimeParser( |
||
35 | new MonthNameUnlocalizer( array() ), |
||
36 | $this->getEraParser(), |
||
0 ignored issues
–
show
|
|||
37 | new IsoTimestampParser( null, $options ) |
||
38 | ); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @return ValueParser |
||
43 | */ |
||
44 | private function getEraParser() { |
||
45 | $mock = $this->createMock( ValueParser::class ); |
||
46 | |||
47 | $mock->expects( $this->any() ) |
||
48 | ->method( 'parse' ) |
||
49 | ->with( $this->isType( 'string' ) ) |
||
50 | ->will( $this->returnCallback( |
||
51 | function ( $value ) { |
||
52 | $sign = '+'; |
||
53 | // Tiny parser that supports a single negative sign only |
||
54 | if ( $value[0] === '-' ) { |
||
55 | $sign = '-'; |
||
56 | $value = substr( $value, 1 ); |
||
57 | } |
||
58 | return array( $sign, $value ); |
||
59 | } |
||
60 | ) ); |
||
61 | |||
62 | return $mock; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @see ValueParserTestBase::validInputProvider |
||
67 | */ |
||
68 | public function validInputProvider() { |
||
69 | $gregorian = 'http://www.wikidata.org/entity/Q1985727'; |
||
70 | $julian = 'http://www.wikidata.org/entity/Q1985786'; |
||
71 | $argList = array(); |
||
72 | |||
73 | $valid = array( |
||
74 | // Whitespace |
||
75 | "10/10/2010\n" => |
||
76 | array( '+0000000000002010-10-10T00:00:00Z' ), |
||
77 | ' 10.10.2010 ' => |
||
78 | array( '+0000000000002010-10-10T00:00:00Z' ), |
||
79 | |||
80 | // Normal/easy dates |
||
81 | ' 10. 10. 2010 ' => |
||
82 | array( '+0000000000002010-10-10T00:00:00Z' ), |
||
83 | '10,10,2010' => |
||
84 | array( '+0000000000002010-10-10T00:00:00Z' ), |
||
85 | '10 10 2010' => |
||
86 | array( '+0000000000002010-10-10T00:00:00Z' ), |
||
87 | '10/10/0010' => |
||
88 | array( '+0000000000000010-10-10T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
89 | '1 July 2013' => |
||
90 | array( '+0000000000002013-07-01T00:00:00Z' ), |
||
91 | '1. July 2013' => |
||
92 | array( '+0000000000002013-07-01T00:00:00Z' ), |
||
93 | '1 July, 2013' => |
||
94 | array( '+0000000000002013-07-01T00:00:00Z' ), |
||
95 | '1 Jul. 2013' => |
||
96 | array( '+0000000000002013-07-01T00:00:00Z' ), |
||
97 | '1 Jul 2013' => |
||
98 | array( '+0000000000002013-07-01T00:00:00Z' ), |
||
99 | 'January 9 1920' => |
||
100 | array( '+0000000000001920-01-09T00:00:00Z' ), |
||
101 | 'Feb 11 1930' => |
||
102 | array( '+0000000000001930-02-11T00:00:00Z' ), |
||
103 | '1st July 2013' => |
||
104 | array( '+0000000000002013-07-01T00:00:00Z' ), |
||
105 | '2nd July 2013' => |
||
106 | array( '+0000000000002013-07-02T00:00:00Z' ), |
||
107 | '3rd July 2013' => |
||
108 | array( '+0000000000002013-07-03T00:00:00Z' ), |
||
109 | '1th July 2013' => |
||
110 | array( '+0000000000002013-07-01T00:00:00Z' ), |
||
111 | '2th July 2013' => |
||
112 | array( '+0000000000002013-07-02T00:00:00Z' ), |
||
113 | '3th July 2013' => |
||
114 | array( '+0000000000002013-07-03T00:00:00Z' ), |
||
115 | '4th July 2013' => |
||
116 | array( '+0000000000002013-07-04T00:00:00Z' ), |
||
117 | |||
118 | // Year first dates |
||
119 | '2009-01-09' => |
||
120 | array( '+0000000000002009-01-09T00:00:00Z' ), |
||
121 | '55-01-09' => |
||
122 | array( '+0000000000000055-01-09T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
123 | '555-01-09' => |
||
124 | array( '+0000000000000555-01-09T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
125 | '33300-1-1' => |
||
126 | array( '+0000000000033300-01-01T00:00:00Z' ), |
||
127 | '3330002-1-1' => |
||
128 | array( '+0000000003330002-01-01T00:00:00Z' ), |
||
129 | |||
130 | // Less than 4 digit years |
||
131 | '10/10/10' => |
||
132 | array( '+0000000000000010-10-10T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
133 | '9 Jan 09' => |
||
134 | array( '+0000000000000009-01-09T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
135 | '1/1/1' => |
||
136 | array( '+0000000000000001-01-01T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
137 | '1-1-1' => |
||
138 | array( '+0000000000000001-01-01T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
139 | '31-1-55' => |
||
140 | array( '+0000000000000055-01-31T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
141 | '10-10-100' => |
||
142 | array( '+0000000000000100-10-10T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
143 | '4th July 11' => |
||
144 | array( '+0000000000000011-07-04T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
145 | '4th July 111' => |
||
146 | array( '+0000000000000111-07-04T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
147 | '4th July 1' => |
||
148 | array( '+0000000000000001-07-04T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
149 | '12.Jun.10x' => |
||
150 | array( '+0000000000000010-06-12T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
151 | |||
152 | // More than 4 digit years |
||
153 | '4th July 10000' => |
||
154 | array( '+0000000000010000-07-04T00:00:00Z' ), |
||
155 | '10/10/22000' => |
||
156 | array( '+0000000000022000-10-10T00:00:00Z' ), |
||
157 | '1-1-33300' => |
||
158 | array( '+0000000000033300-01-01T00:00:00Z' ), |
||
159 | '4th July 7214614279199781' => |
||
160 | array( '+7214614279199781-07-04T00:00:00Z' ), |
||
161 | '-10100-02-29' => |
||
162 | array( '-0000000000010100-03-01T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
163 | |||
164 | // Years with leading zeros |
||
165 | '009-08-07' => |
||
166 | array( '+0000000000000009-08-07T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
167 | '000001-07-04' => |
||
168 | array( '+0000000000000001-07-04T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
169 | '0000001-07-04' => |
||
170 | array( '+0000000000000001-07-04T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
171 | '00000001-07-04' => |
||
172 | array( '+0000000000000001-07-04T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
173 | '000000001-07-04' => |
||
174 | array( '+0000000000000001-07-04T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
175 | '00000000000-07-04' => |
||
176 | array( '+0000000000000000-07-04T00:00:00Z', TimeValue::PRECISION_DAY, $julian ), |
||
177 | '4th July 00000002015' => |
||
178 | array( '+0000000000002015-07-04T00:00:00Z' ), |
||
179 | '00000002015-07-04' => |
||
180 | array( '+0000000000002015-07-04T00:00:00Z' ), |
||
181 | '4th July 00000092015' => |
||
182 | array( '+0000000000092015-07-04T00:00:00Z' ), |
||
183 | '00000092015-07-04' => |
||
184 | array( '+0000000000092015-07-04T00:00:00Z' ), |
||
185 | |||
186 | // Hour, minute and second precision |
||
187 | '4 July 2015 23:59' => |
||
188 | array( '+0000000000002015-07-04T23:59:00Z', TimeValue::PRECISION_MINUTE ), |
||
189 | '4 July 100 23:59' => |
||
190 | array( '+0000000000000100-07-04T23:59:00Z', TimeValue::PRECISION_MINUTE, $julian ), |
||
191 | '4 July 015 23:59' => |
||
192 | array( '+0000000000000015-07-04T23:59:00Z', TimeValue::PRECISION_MINUTE, $julian ), |
||
193 | '4 July 15 23:59' => |
||
194 | array( '+0000000000000015-07-04T23:59:00Z', TimeValue::PRECISION_MINUTE, $julian ), |
||
195 | '4.7.015 23:59' => |
||
196 | array( '+0000000000000015-07-04T23:59:00Z', TimeValue::PRECISION_MINUTE, $julian ), |
||
197 | '4.7.15 23:59' => |
||
198 | array( '+0000000000000015-07-04T23:59:00Z', TimeValue::PRECISION_MINUTE, $julian ), |
||
199 | '4/7/015 23:59' => |
||
200 | array( '+0000000000000015-04-07T23:59:00Z', TimeValue::PRECISION_MINUTE, $julian ), |
||
201 | '4/7/15 23:59' => |
||
202 | array( '+0000000000000015-04-07T23:59:00Z', TimeValue::PRECISION_MINUTE, $julian ), |
||
203 | '4th July 2015 12:00' => |
||
204 | array( '+0000000000002015-07-04T12:00:00Z', TimeValue::PRECISION_HOUR ), |
||
205 | '2015-07-04 12:00' => |
||
206 | array( '+0000000000002015-07-04T12:00:00Z', TimeValue::PRECISION_HOUR ), |
||
207 | '2015-07-04 12:30' => |
||
208 | array( '+0000000000002015-07-04T12:30:00Z', TimeValue::PRECISION_MINUTE ), |
||
209 | '2015-07-04 12:30:29' => |
||
210 | array( '+0000000000002015-07-04T12:30:29Z', TimeValue::PRECISION_SECOND ), |
||
211 | '15.07.04 23:59' => |
||
212 | array( '+0000000000000004-07-15T23:59:00Z', TimeValue::PRECISION_MINUTE, $julian ), |
||
213 | '15.07.04 00:01' => |
||
214 | array( '+0000000000000004-07-15T00:01:00Z', TimeValue::PRECISION_MINUTE, $julian ), |
||
215 | '15-07-01 12:37:00' => |
||
216 | array( '+0000000000000001-07-15T12:37:00Z', TimeValue::PRECISION_MINUTE, $julian ), |
||
217 | '4th July 15 12:00' => |
||
218 | array( '+0000000000000015-07-04T12:00:00Z', TimeValue::PRECISION_HOUR, $julian ), |
||
219 | 'July 4th 15 12:00' => |
||
220 | array( '+0000000000000015-07-04T12:00:00Z', TimeValue::PRECISION_HOUR, $julian ), |
||
221 | |||
222 | // Testing leap year stuff |
||
223 | '10000-02-29' => |
||
224 | array( '+0000000000010000-02-29T00:00:00Z' ), |
||
225 | '10100-02-29' => |
||
226 | array( '+0000000000010100-03-01T00:00:00Z' ), |
||
227 | '10400-02-29' => |
||
228 | array( '+0000000000010400-02-29T00:00:00Z' ), |
||
229 | |||
230 | 'Jan1 1991' => |
||
231 | array( '+1991-01-01T00:00:00Z' ), |
||
232 | '1991-1-1' => |
||
233 | array( '+1991-01-01T00:00:00Z' ), |
||
234 | '1991/1/1' => |
||
235 | array( '+1991-01-01T00:00:00Z' ), |
||
236 | '1991 1 1' => |
||
237 | array( '+1991-01-01T00:00:00Z' ), |
||
238 | '1991.1.1' => |
||
239 | array( '+1991-01-01T00:00:00Z' ), |
||
240 | '1991.01.01' => |
||
241 | array( '+1991-01-01T00:00:00Z' ), |
||
242 | ); |
||
243 | |||
244 | foreach ( $valid as $value => $args ) { |
||
245 | $timestamp = $args[0]; |
||
246 | $precision = isset( $args[1] ) ? $args[1] : TimeValue::PRECISION_DAY; |
||
247 | $calendarModel = isset( $args[2] ) ? $args[2] : $gregorian; |
||
248 | |||
249 | $argList[] = array( |
||
250 | // Because PHP magically turns numeric keys into ints/floats |
||
251 | (string)$value, |
||
252 | new TimeValue( $timestamp, 0, 0, 0, $precision, $calendarModel ) |
||
253 | ); |
||
254 | } |
||
255 | |||
256 | return $argList; |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * @see StringValueParserTest::invalidInputProvider |
||
261 | */ |
||
262 | public function invalidInputProvider() { |
||
263 | $argLists = parent::NON_VALID_CASES; |
||
264 | |||
265 | $invalid = array( |
||
266 | 'June June June', |
||
267 | '111 111 111', |
||
268 | '101st July 2015', |
||
269 | '2015-07-101', |
||
270 | '10 .10 .2010', |
||
271 | '10...10...2010', |
||
272 | '00-00-00', |
||
273 | '99-00-00', |
||
274 | '111-00-00', |
||
275 | '2015-00-00', |
||
276 | '00000000099-00-00', |
||
277 | '00000002015-00-00', |
||
278 | '92015-00-00', |
||
279 | 'Jann 2014', |
||
280 | '1980x', |
||
281 | '1980s', |
||
282 | '1980', |
||
283 | '1980ss', |
||
284 | '1980er', |
||
285 | '1980UTC', |
||
286 | '1980America/New_York', |
||
287 | '1980 America/New_York', |
||
288 | '1980+3', |
||
289 | '1980+x', |
||
290 | 'x', |
||
291 | 'x x x', |
||
292 | 'zz', |
||
293 | 'America/New_York', |
||
294 | '1991 2', |
||
295 | ', 1966', |
||
296 | ); |
||
297 | |||
298 | foreach ( $invalid as $value ) { |
||
299 | $argLists[] = array( $value ); |
||
300 | } |
||
301 | |||
302 | return $argLists; |
||
303 | } |
||
304 | |||
305 | } |
||
306 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: