Skip to content

Commit 51eefbf

Browse files
author
Benjamin Nobis
committed
Fix string including comma
1 parent 91b29ff commit 51eefbf

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/PadsJson.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function padObject($tmpJson)
7171
}
7272

7373
$part = \substr($tmpJson, $this->objectPos + 1);
74-
if (\preg_match('/(\s*\"[^"]+\"\s*:\s*[^,]+,?)+$/', $part, $matches)) {
74+
if (\preg_match('/(\s*\"[^"]+\"\s*:\s*([^,]+|\"(?:.(?!(?<![\\\\])"))*.?"?),?)+$/', $part, $matches)) {
7575
return $tmpJson;
7676
}
7777

tests/FixerTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ public function theTests()
160160
], [
161161
'json' => '[ {"id":1, "data": []}, {"id":2, "data": [',
162162
'expect' => '[ {"id":1, "data": []}, {"id":2, "data": []}]',
163+
], [
164+
'json' => '[ {"id":1, "data": []}, {"id":2, "data": "bla,',
165+
'expect' => '[ {"id":1, "data": []}, {"id":2, "data": "bla,"}]',
163166
],
164167
];
165168
}

0 commit comments

Comments
 (0)