Skip to content

Commit 731f5fc

Browse files
committed
fix: negative numbers had the wrong type
1 parent bc0d909 commit 731f5fc

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"ext-mbstring": "*"
3232
},
3333
"require-dev": {
34-
"ext-json": "*"
34+
"ext-json": "*",
35+
"phpunit/phpunit": "~9.6"
3536
},
3637
"autoload": {
3738
"psr-4": {

src/ParserHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function convertCodepointToCharacter(int $char): string
4747
public static function convertToNumber(string $text)
4848
{
4949
// thanks to #andig for the fix for big integers
50-
if (ctype_digit($text) && (float) $text === (float) ((int) $text)) {
50+
if (filter_var($text, FILTER_VALIDATE_INT) && (float) $text === (float) ((int) $text)) {
5151
// natural number PHP_INT_MIN < $num < PHP_INT_MAX
5252
return (int) $text;
5353
}

tests/RegexListenerTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,13 @@ public function testBasicArrayReadCapture(): void
352352
->getMock()
353353
;
354354

355-
$valueCall->expects($this->exactly(2))
355+
$valueCall->expects($this->exactly(3))
356356
->method('__invoke')
357-
->withConsecutive(['1', '/0'],
358-
['2', '/1'])
357+
->withConsecutive(
358+
['1', '/0'],
359+
['2', '/1'],
360+
['-1', '/2']
361+
)
359362
;
360363

361364
$listener = new RegexListener(["(/\d*)" => $valueCall]);

tests/data/simpleArray.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[1,2]
1+
[1,2,-1]

0 commit comments

Comments
 (0)