Skip to content

Commit 1287062

Browse files
committed
Use JsonFile::encode instead of casting to string to make sure we do not hide json errors
1 parent bdc0d7b commit 1287062

File tree

9 files changed

+12
-10
lines changed

9 files changed

+12
-10
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
],
2424
"require": {
2525
"php": "^7.2.5 || ^8.0",
26+
"ext-json": "*",
2627
"composer/ca-bundle": "^1.5",
2728
"composer/class-map-generator": "^1.4.0",
2829
"composer/metadata-minifier": "^1.0",

composer.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Composer/Json/JsonFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public static function validateJsonSchema(string $source, $data, int $schema, ?s
276276
* @param string $indent Indentation string
277277
* @return string Encoded json
278278
*/
279-
public static function encode($data, int $options = 448, string $indent = self::INDENT_DEFAULT): string
279+
public static function encode($data, int $options = \JSON_UNESCAPED_SLASHES|\JSON_PRETTY_PRINT|\JSON_UNESCAPED_UNICODE, string $indent = self::INDENT_DEFAULT): string
280280
{
281281
$json = json_encode($data, $options);
282282

src/Composer/Repository/Vcs/ForgejoDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function getComposerInformation(string $identifier): ?array
162162
$composer = $this->getBaseComposerInformation($identifier);
163163

164164
if ($this->shouldCache($identifier)) {
165-
$this->cache->write($identifier, (string) json_encode($composer));
165+
$this->cache->write($identifier, JsonFile::encode($composer, \JSON_UNESCAPED_UNICODE|\JSON_UNESCAPED_SLASHES));
166166
}
167167
}
168168

src/Composer/Repository/Vcs/GitBitbucketDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function getComposerInformation(string $identifier): ?array
147147
$composer = $this->getBaseComposerInformation($identifier);
148148

149149
if ($this->shouldCache($identifier)) {
150-
$this->cache->write($identifier, (string) json_encode($composer));
150+
$this->cache->write($identifier, JsonFile::encode($composer, \JSON_UNESCAPED_UNICODE|\JSON_UNESCAPED_SLASHES));
151151
}
152152
}
153153

src/Composer/Repository/Vcs/GitHubDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function getComposerInformation(string $identifier): ?array
166166
$composer = $this->getBaseComposerInformation($identifier);
167167

168168
if ($this->shouldCache($identifier)) {
169-
$this->cache->write($identifier, (string) json_encode($composer));
169+
$this->cache->write($identifier, JsonFile::encode($composer, \JSON_UNESCAPED_UNICODE|\JSON_UNESCAPED_SLASHES));
170170
}
171171
}
172172

src/Composer/Repository/Vcs/GitLabDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function getComposerInformation(string $identifier): ?array
159159
$composer = $this->getBaseComposerInformation($identifier);
160160

161161
if ($this->shouldCache($identifier)) {
162-
$this->cache->write($identifier, (string) json_encode($composer));
162+
$this->cache->write($identifier, JsonFile::encode($composer, \JSON_UNESCAPED_UNICODE|\JSON_UNESCAPED_SLASHES));
163163
}
164164
}
165165

src/Composer/Repository/Vcs/SvnDriver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function getComposerInformation(string $identifier): ?array
141141
// and fix outdated invalid cache files
142142
if ($res === '""') {
143143
$res = 'null';
144-
$this->cache->write($identifier.'.json', (string) json_encode(null));
144+
$this->cache->write($identifier.'.json', $res);
145145
}
146146

147147
return $this->infoCache[$identifier] = JsonFile::parseJson($res);
@@ -159,7 +159,7 @@ public function getComposerInformation(string $identifier): ?array
159159
}
160160

161161
if ($this->shouldCache($identifier)) {
162-
$this->cache->write($identifier.'.json', (string) json_encode($composer));
162+
$this->cache->write($identifier.'.json', JsonFile::encode($composer, \JSON_UNESCAPED_UNICODE|\JSON_UNESCAPED_SLASHES));
163163
}
164164

165165
$this->infoCache[$identifier] = $composer;

src/Composer/Repository/Vcs/VcsDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function getComposerInformation(string $identifier): ?array
9595
$composer = $this->getBaseComposerInformation($identifier);
9696

9797
if ($this->shouldCache($identifier)) {
98-
$this->cache->write($identifier, JsonFile::encode($composer, 0));
98+
$this->cache->write($identifier, JsonFile::encode($composer, \JSON_UNESCAPED_UNICODE|\JSON_UNESCAPED_SLASHES));
9999
}
100100

101101
$this->infoCache[$identifier] = $composer;

0 commit comments

Comments
 (0)