Skip to content

Commit 7c875f6

Browse files
do not allow negative leading zeros (#812)
1 parent 1a23f0e commit 7c875f6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Number.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private static function parseIntegerPart(string $number): string
225225
return '0';
226226
}
227227

228-
if ($number === '-') {
228+
if ($number === '-' || $number === '-0') {
229229
return '-0';
230230
}
231231

@@ -244,6 +244,10 @@ private static function parseIntegerPart(string $number): string
244244
throw new InvalidArgumentException(sprintf('Invalid integer part %1$s. Invalid digit %2$s found', $number, $digit));
245245
}
246246

247+
if ($digit === '-') {
248+
continue;
249+
}
250+
247251
if ($nonZero === false && $digit === '0') {
248252
throw new InvalidArgumentException('Leading zeros are not allowed');
249253
}

tests/NumberTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public static function invalidNumberExamples(): array
166166
[''],
167167
['000'],
168168
['005'],
169+
['-005'],
169170
['123456789012345678-123456'],
170171
['---123'],
171172
['123456789012345678+13456'],

0 commit comments

Comments
 (0)