Skip to content

Commit 3062f05

Browse files
committed
bug #59769 Enable JSON_PRESERVE_ZERO_FRACTION in jsonRequest method (raffaelecarelle)
This PR was submitted for the 7.2 branch but it was squashed and merged into the 6.4 branch instead. Discussion ---------- Enable `JSON_PRESERVE_ZERO_FRACTION` in `jsonRequest` method | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT Updated the jsonRequest method to use JSON_PRESERVE_ZERO_FRACTION when encoding parameters. This avoid unintended cast to int. Test case: ``` $this->browser->jsonRequest('GET', 'url', ['cost' => 10.0]); ``` "cost" will be cast to int `10` Commits ------- 535953e Enable `JSON_PRESERVE_ZERO_FRACTION` in `jsonRequest` method
2 parents db15145 + 535953e commit 3062f05

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Symfony/Component/BrowserKit/AbstractBrowser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function xmlHttpRequest(string $method, string $uri, array $parameters =
170170
*/
171171
public function jsonRequest(string $method, string $uri, array $parameters = [], array $server = [], bool $changeHistory = true): Crawler
172172
{
173-
$content = json_encode($parameters);
173+
$content = json_encode($parameters, \JSON_PRESERVE_ZERO_FRACTION);
174174

175175
$this->setServerParameter('CONTENT_TYPE', 'application/json');
176176
$this->setServerParameter('HTTP_ACCEPT', 'application/json');

src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ public function testXmlHttpRequest()
6767
public function testJsonRequest()
6868
{
6969
$client = $this->getBrowser();
70-
$client->jsonRequest('GET', 'http://example.com/', ['param' => 1], [], true);
70+
$client->jsonRequest('GET', 'http://example.com/', ['param' => 1, 'float' => 10.0], [], true);
7171
$this->assertSame('application/json', $client->getRequest()->getServer()['CONTENT_TYPE']);
7272
$this->assertSame('application/json', $client->getRequest()->getServer()['HTTP_ACCEPT']);
7373
$this->assertFalse($client->getServerParameter('CONTENT_TYPE', false));
7474
$this->assertFalse($client->getServerParameter('HTTP_ACCEPT', false));
75-
$this->assertSame('{"param":1}', $client->getRequest()->getContent());
75+
$this->assertSame('{"param":1,"float":10.0}', $client->getRequest()->getContent());
7676
}
7777

7878
public function testGetRequestWithIpAsHttpHost()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy