close
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Verify json decoding worked
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
  • Loading branch information
swissspidy and Copilot authored Nov 2, 2025
commit 47501728bc43049fb883f0ffcc24fe9fb16ab687
7 changes: 6 additions & 1 deletion src/Spyc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,12 @@ private function returnKeyValuePair ($line) {
$this->checkKeysInValue($value);
// Other methods currently don't parse valid json maps or arrays of maps correctly
if ( str_starts_with( $value, '[{' ) || str_starts_with( $value, '{"' ) ) {
$value = json_decode( preg_replace( '/^.*?:\s*/', '', $line ), true );
$decoded = json_decode( preg_replace( '/^.*?:\s*/', '', $line ), true );
if ($decoded !== null || (json_last_error() === JSON_ERROR_NONE && $decoded === null)) {
// Accept null as valid JSON value, but only if no error occurred
$value = $decoded;
}
// Otherwise, leave $value as-is (fallback to original string)
}
}
// Set the type of the value. Int, string, etc
Expand Down