From 82318c6df0bd28f4d7a5c3d6f35939cd686df7f8 Mon Sep 17 00:00:00 2001 From: Max Pozdeev Date: Fri, 15 Apr 2022 21:29:59 +0300 Subject: [PATCH] prevent possible errors if language files are broken --- src/includes/class.lang.php | 6 ++++++ src/settings.php | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/includes/class.lang.php b/src/includes/class.lang.php index 65ee328..04fc370 100644 --- a/src/includes/class.lang.php +++ b/src/includes/class.lang.php @@ -60,6 +60,9 @@ class Lang { $this->code = $code; $json = json_decode($jsonString, true); + if ($json === null) { + $json = array(); + } //load default language if ( $code != $this->default ) { @@ -78,6 +81,9 @@ class Lang } $defStr = file_get_contents($this->langDir(). "{$this->default}.json"); $this->strings = json_decode($defStr, true); + if ($this->strings === null) { + die("Invalid JSON in default language file (". htmlspecialchars($this->default). ".json)"); + } } function get($key) diff --git a/src/settings.php b/src/settings.php index a5c43df..6214270 100644 --- a/src/settings.php +++ b/src/settings.php @@ -114,6 +114,9 @@ function selectOptionsA($a, $key, $default=null) $s = ''; if($default !== null && !isset($a[$key])) $key = $default; foreach($a as $k=>$v) { + if (!is_array($v)) { + $v = array('name' => $k); + } $s .= ''; @@ -141,7 +144,7 @@ header('Content-type:text/html; charset=utf-8'); if (isset($_GET['json'])) { $j = Config::requestDefaultDomain(); if ($j['password'] != '') $j['password'] = ""; - $j = json_encode($j, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); + $j = json_encode($j, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_INVALID_UTF8_SUBSTITUTE); ?>
@@ -269,4 +272,4 @@ header('Content-type:text/html; charset=utf-8');
- \ No newline at end of file +