8000 minor #48100 [HttpFoundation][Validator] Leverage `json_validate()` (… · symfony/symfony@1b3d301 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 1b3d301

Browse files
committed
minor #48100 [HttpFoundation][Validator] Leverage json_validate() (derrabus)
This PR was merged into the 6.3 branch. Discussion ---------- [HttpFoundation][Validator] Leverage `json_validate()` | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | Not needed Let's make use of symfony/polyfill#416. Commits ------- d2b6b49 [HttpFoundation][Validator] Leverage json_validate()
2 parents 13059f6 + d2b6b49 commit 1b3d301

File tree

5 files changed

+6
-11
lines changed

5 files changed

+6
-11
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"symfony/polyfill-intl-idn": "^1.10",
5454
"symfony/polyfill-intl-normalizer": "~1.0",
5555
"symfony/polyfill-mbstring": "~1.0",
56+
"symfony/polyfill-php83": "^1.27",
5657
"symfony/polyfill-uuid": "^1.15"
5758
},
5859
"replace": {

src/Symfony/Component/HttpFoundation/RequestMatcher/IsJsonRequestMatcher.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ class IsJsonRequestMatcher implements RequestMatcherInterface
2323
{
2424
public function matches(Request $request): bool
2525
{
26-
try {
27-
json_decode($request->getContent(), true, 512, \JSON_BIGINT_AS_STRING | \JSON_THROW_ON_ERROR);
28-
} catch (\JsonException) {
29-
return false;
30-
}
31-
32-
return true;
26+
return json_validate($request->getContent());
3327
}
3428
}

src/Symfony/Component/HttpFoundation/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"require": {
1919
"php": ">=8.1",
2020
"symfony/deprecation-contracts": "^2.1|^3",
21-
"symfony/polyfill-mbstring": "~1.1"
21+
"symfony/polyfill-mbstring": "~1.1",
22+
"symfony/polyfill-php83": "^1.27"
2223
},
2324
"require-dev": {
2425
"predis/predis": "~1.0",

src/Symfony/Component/Validator/Constraints/JsonValidator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ public function validate(mixed $value, Constraint $constraint)
3636

3737
$value = (string) $value;
3838

39-
json_decode($value);
40-
41-
if (\JSON_ERROR_NONE !== json_last_error()) {
39+
if (!json_validate($value)) {
4240
$this->context->buildViolation($constraint->message)
4341
->setParameter('{{ value }}', $this->formatValue($value))
4442
->setCode(Json::INVALID_JSON_ERROR)

src/Symfony/Component/Validator/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"symfony/deprecation-contracts": "^2.1|^3",
2121
"symfony/polyfill-ctype": "~1.8",
2222
"symfony/polyfill-mbstring": "~1.0",
23+
"symfony/polyfill-php83": "^1.27",
2324
"symfony/translation-contracts": "^1.1|^2|^3"
2425
},
2526
"require-dev": {

0 commit comments

Comments
 (0)
0