From 89d58f4f5b2efa677c02ff9ea75861ed08ce9406 Mon Sep 17 00:00:00 2001 From: otsch Date: Wed, 20 Nov 2024 01:43:07 +0100 Subject: [PATCH] Another fix for unescaped double quotes --- CHANGELOG.md | 4 ++++ src/Json.php | 20 ++++++++++++-------- tests/JsonTest.php | 12 ++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0fb783..6d6342a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.1.2] - 2024-11-20 +### Fixed +- Another improvement for parsing invalid JSON with unescaped double quote characters inside string values. + ## [1.1.1] - 2024-11-20 ### Fixed - Improve parsing invalid JSON by detecting and fixing unescaped double quote characters inside string values. diff --git a/src/Json.php b/src/Json.php index 1e344c2..7e8a156 100644 --- a/src/Json.php +++ b/src/Json.php @@ -66,14 +66,18 @@ function ($match) { ) ?? $jsonString; // If JSON string contains unescaped double quotes inside a string value, try to fix it. - if (preg_match('/".+?": "(.+(?toBe([ + 'foo' => 'bar', + 'description' => 'lorem "ipsum" asdf', + 'baz' => 'quz "yo" "" "lo"', + ]); +}); + it('throws an exception when the string is not a (valid) JSON string', function () { Json::stringToArray('{ foo: bar ]'); })->throws(InvalidJsonException::class);