Skip to content

Commit

Permalink
Merge pull request #97 from taka-oyama/master
Browse files Browse the repository at this point in the history
fix: negative numbers return the wrong type
  • Loading branch information
gonzofy authored Apr 14, 2023
2 parents bc0d909 + 731f5fc commit 6f1a5d4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"ext-mbstring": "*"
},
"require-dev": {
"ext-json": "*"
"ext-json": "*",
"phpunit/phpunit": "~9.6"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/ParserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function convertCodepointToCharacter(int $char): string
public static function convertToNumber(string $text)
{
// thanks to #andig for the fix for big integers
if (ctype_digit($text) && (float) $text === (float) ((int) $text)) {
if (filter_var($text, FILTER_VALIDATE_INT) && (float) $text === (float) ((int) $text)) {
// natural number PHP_INT_MIN < $num < PHP_INT_MAX
return (int) $text;
}
Expand Down
9 changes: 6 additions & 3 deletions tests/RegexListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,13 @@ public function testBasicArrayReadCapture(): void
->getMock()
;

$valueCall->expects($this->exactly(2))
$valueCall->expects($this->exactly(3))
->method('__invoke')
->withConsecutive(['1', '/0'],
['2', '/1'])
->withConsecutive(
['1', '/0'],
['2', '/1'],
['-1', '/2']
)
;

$listener = new RegexListener(["(/\d*)" => $valueCall]);
Expand Down
2 changes: 1 addition & 1 deletion tests/data/simpleArray.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[1,2]
[1,2,-1]

0 comments on commit 6f1a5d4

Please sign in to comment.