Skip to content

Commit 3bb2e3f

Browse files
committed
clean asset data json
1 parent bc93798 commit 3bb2e3f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Actions/VerifyThemeSupport.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,14 @@ private function mainSections(ShopModel $shop, array $mainTheme, array $assets):
9090
{
9191
$filenamesForMainSections = array_filter(
9292
array_map(function ($asset) {
93-
$assetContent = json_decode($asset['content'], true);
93+
$content = $asset['content'];
94+
95+
if (! $this->json_validate($content)) {
96+
$content = preg_replace("#(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|([\s\t]//.*)|(^//.*)#", '', $content);
97+
}
98+
99+
$assetContent = json_decode($content, true);
100+
94101

95102
$mainAsset = array_filter($assetContent['sections'], function ($value, $key) {
96103
return $key == self::MAIN_ROLE || str_starts_with($value['type'], self::MAIN_ROLE);
@@ -134,4 +141,12 @@ private function sectionsWithAppBlock(array $templateMainSections): array
134141
return $acceptsAppBlock ? $file : null;
135142
}, $templateMainSections));
136143
}
144+
145+
146+
private function json_validate(string $string): bool
147+
{
148+
json_decode($string);
149+
150+
return json_last_error() === JSON_ERROR_NONE;
151+
}
137152
}

0 commit comments

Comments
 (0)