File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed
Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments