Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kesselberg <mail@danielkesselberg.de>2019-12-08 19:20:50 +0300
committerDaniel Kesselberg <mail@danielkesselberg.de>2019-12-09 14:09:43 +0300
commit64aba49461114b986952ece89ea9467618a0ab19 (patch)
tree7db03718f589f8e610836f3221d5a98cd8c1064c /lib/private/Files/Type/Detection.php
parent8bc4295cfad1ba65bad3c7c06af1f4a16b9bcba5 (diff)
Ensure that we don't merge broken json.
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'lib/private/Files/Type/Detection.php')
-rw-r--r--lib/private/Files/Type/Detection.php31
1 files changed, 25 insertions, 6 deletions
diff --git a/lib/private/Files/Type/Detection.php b/lib/private/Files/Type/Detection.php
index 20758a71f87..f58431efee5 100644
--- a/lib/private/Files/Type/Detection.php
+++ b/lib/private/Files/Type/Detection.php
@@ -35,6 +35,7 @@
namespace OC\Files\Type;
use OCP\Files\IMimeTypeDetector;
+use OCP\ILogger;
use OCP\IURLGenerator;
/**
@@ -45,6 +46,10 @@ use OCP\IURLGenerator;
* @package OC\Files\Type
*/
class Detection implements IMimeTypeDetector {
+
+ public const CUSTOM_MIMETYPEMAPPING = 'mimetypemapping.json';
+ public const CUSTOM_MIMETYPEALIASES = 'mimetypealiases.json';
+
protected $mimetypes = [];
protected $secureMimeTypes = [];
@@ -55,6 +60,9 @@ class Detection implements IMimeTypeDetector {
/** @var IURLGenerator */
private $urlGenerator;
+ /** @var ILogger */
+ private $logger;
+
/** @var string */
private $customConfigDir;
@@ -63,13 +71,16 @@ class Detection implements IMimeTypeDetector {
/**
* @param IURLGenerator $urlGenerator
+ * @param ILogger $logger
* @param string $customConfigDir
* @param string $defaultConfigDir
*/
public function __construct(IURLGenerator $urlGenerator,
+ ILogger $logger,
$customConfigDir,
$defaultConfigDir) {
$this->urlGenerator = $urlGenerator;
+ $this->logger = $logger;
$this->customConfigDir = $customConfigDir;
$this->defaultConfigDir = $defaultConfigDir;
}
@@ -120,9 +131,13 @@ class Detection implements IMimeTypeDetector {
$this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true);
- if (file_exists($this->customConfigDir . '/mimetypealiases.json')) {
- $custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypealiases.json'), true);
- $this->mimeTypeAlias = array_merge($this->mimeTypeAlias, $custom);
+ if (file_exists($this->customConfigDir . '/' . self::CUSTOM_MIMETYPEALIASES)) {
+ $custom = json_decode(file_get_contents($this->customConfigDir . '/' . self::CUSTOM_MIMETYPEALIASES), true);
+ if (json_last_error() === JSON_ERROR_NONE) {
+ $this->mimeTypeAlias = array_merge($this->mimeTypeAlias, $custom);
+ } else {
+ $this->logger->warning('Failed to parse ' . self::CUSTOM_MIMETYPEALIASES . ': ' . json_last_error_msg());
+ }
}
}
@@ -151,9 +166,13 @@ class Detection implements IMimeTypeDetector {
$mimetypeMapping = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypemapping.dist.json'), true);
//Check if need to load custom mappings
- if (file_exists($this->customConfigDir . '/mimetypemapping.json')) {
- $custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypemapping.json'), true);
- $mimetypeMapping = array_merge($mimetypeMapping, $custom);
+ if (file_exists($this->customConfigDir . '/' . self::CUSTOM_MIMETYPEMAPPING)) {
+ $custom = json_decode(file_get_contents($this->customConfigDir . '/' . self::CUSTOM_MIMETYPEMAPPING), true);
+ if (json_last_error() === JSON_ERROR_NONE) {
+ $mimetypeMapping = array_merge($mimetypeMapping, $custom);
+ } else {
+ $this->logger->warning('Failed to parse ' . self::CUSTOM_MIMETYPEMAPPING . ': ' . json_last_error_msg());
+ }
}
$this->registerTypeArray($mimetypeMapping);