Skip to content

Commit 0e26ae9

Browse files
authored
Update Html.php
1 parent 9b73ba8 commit 0e26ae9

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Model/Parser/Html.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,20 +187,21 @@ private function getProductIds(string $html): array
187187

188188
return $productIds;
189189
}
190-
190+
191191
private function json_validate($json, $depth = 512, $flags = 0)
192192
{
193-
// First character check to ensure the string starts with `{` or `[` (to improve perfrormace)
194-
$trimmedJson = ltrim($json);
195-
if (!is_string($json) || ($trimmedJson[0] !== '{' && $trimmedJson[0] !== '[')) {
193+
if (!is_string($json)) {
196194
return false;
197195
}
198196

199-
try {
200-
json_decode($json, false, $depth, $flags | JSON_THROW_ON_ERROR);
201-
return true;
202-
} catch (\JsonException $e) {
197+
$trimmedJson = ltrim($json);
198+
// First character check to ensure the string starts with `{` or `[` (to improve perfrormace)
199+
if ($trimmedJson[0] !== '{' && $trimmedJson[0] !== '[') {
203200
return false;
204201
}
202+
203+
// Decode JSON and check for errors
204+
json_decode($json, false, $depth, $flags);
205+
return json_last_error() === JSON_ERROR_NONE;
205206
}
206207
}

0 commit comments

Comments
 (0)