Skip to content

Commit 7bb9376

Browse files
committed
Guard against corrupt json file
1 parent 0269602 commit 7bb9376

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎error.php‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,14 @@
204204
// 'in_manual' - manual URI (/manual/{lang}/{from}[.php]) -> /manual/{lang}/{to}.php
205205
// 'both' - matches at either entry point
206206

207-
$docRedirects = is_file(__DIR__ . '/manual/en/redirects.json')
208-
? json_decode(file_get_contents(__DIR__ . '/manual/en/redirects.json'), true)
209-
: ['shortcut' => [], 'in_manual' => [], 'both' => []];
207+
$docRedirectsFile = __DIR__ . '/manual/en/redirects.json';
208+
$docRedirects = is_file($docRedirectsFile)
209+
? json_decode(file_get_contents($docRedirectsFile), true)
210+
: null;
211+
if (!is_array($docRedirects)) {
212+
// Redirects file is corrupt or missing.
213+
$docRedirects = [];
214+
}
210215

211216
if (preg_match("!^manual/([^/]+)/([^/]+?)(?:\.php)?$!", $URI, $match)) {
212217
$target = $docRedirects['both'][$match[2]] ?? $docRedirects['in_manual'][$match[2]] ?? null;

0 commit comments

Comments
 (0)