From d912b618b3868dae1e64e4cfca2fd8e3be3e7d30 Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Fri, 8 Sep 2023 09:06:30 +0200 Subject: [PATCH] Revert float convertion --- interfaces/KeyValuePair/Converter.php | 5 ++--- interfaces/KeyValuePair/ConverterTest.php | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/interfaces/KeyValuePair/Converter.php b/interfaces/KeyValuePair/Converter.php index 17ea0800..7097b8e8 100644 --- a/interfaces/KeyValuePair/Converter.php +++ b/interfaces/KeyValuePair/Converter.php @@ -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, }; @@ -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( diff --git a/interfaces/KeyValuePair/ConverterTest.php b/interfaces/KeyValuePair/ConverterTest.php index 97ea2332..957e5948 100644 --- a/interfaces/KeyValuePair/ConverterTest.php +++ b/interfaces/KeyValuePair/ConverterTest.php @@ -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'));