Skip to content

Commit

Permalink
Revert float convertion
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Sep 8, 2023
1 parent 64ef3c8 commit d912b61
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions interfaces/KeyValuePair/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public function toPairs(Stringable|string|int|float|bool|null $value): array
$value instanceof Stringable, is_int($value) => (string) $value,
false === $value => '0',
true === $value => '1',
is_float($value) => (string) json_encode($value, JSON_PRESERVE_ZERO_FRACTION),
default => $value,
};

Expand All @@ -133,8 +132,8 @@ public function toPairs(Stringable|string|int|float|bool|null $value): array
}

$value = match (1) {
preg_match(self::REGEXP_INVALID_CHARS, $value) => throw new SyntaxError('Invalid query string: `'.$value.'`.'),
default => str_replace($this->toEncoding, $this->fromRfc3986, $value),
preg_match(self::REGEXP_INVALID_CHARS, (string) $value) => throw new SyntaxError('Invalid query string: `'.$value.'`.'),
default => str_replace($this->toEncoding, $this->fromRfc3986, (string) $value),
};

return array_map(
Expand Down
2 changes: 1 addition & 1 deletion interfaces/KeyValuePair/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testDecodingByType(): void
self::assertSame([], $converter->toPairs(null));
self::assertSame([['', null]], $converter->toPairs(''));
self::assertSame([['42', null]], $converter->toPairs(42));
self::assertSame([['42.0', null]], $converter->toPairs(42.000));
self::assertSame([['42', null]], $converter->toPairs(42.000));
self::assertSame([['0', null]], $converter->toPairs(false));
self::assertSame([['1', null]], $converter->toPairs(true));
self::assertSame([['string', null]], $converter->toPairs('string'));
Expand Down

0 comments on commit d912b61

Please sign in to comment.