From 71474fc66ec6fb3cfa2ce4cb8b8224413caa0020 Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 2 Feb 2021 19:01:43 +0000 Subject: [PATCH 1/2] [FormatFactory] Allow lowercase format value --- lib/FormatFactory.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/FormatFactory.php b/lib/FormatFactory.php index 28db7596ffb..017a19216a8 100644 --- a/lib/FormatFactory.php +++ b/lib/FormatFactory.php @@ -46,7 +46,13 @@ public function create($name){ throw new \InvalidArgumentException('Format name invalid!'); } - $name = $this->sanitizeFormatName($name) . 'Format'; + $name = $this->sanitizeFormatName($name); + + if (is_null($name)) { + throw new \InvalidArgumentException('Unknown format given!'); + } + + $name .= 'Format'; $pathFormat = $this->getWorkingDir() . $name . '.php'; if(!file_exists($pathFormat)) { @@ -72,7 +78,7 @@ public function create($name){ * @return bool true if the name is a valid format name, false otherwise. */ public function isFormatName($name){ - return is_string($name) && preg_match('/^[A-Z][a-zA-Z0-9-]*$/', $name) === 1; + return is_string($name) && preg_match('/^[a-zA-Z0-9-]*$/', $name) === 1; } /** @@ -108,8 +114,6 @@ public function getFormatNames(){ * * The PHP file name without file extension (i.e. `AtomFormat`) * * The format name (i.e. `Atom`) * - * Casing is ignored (i.e. `ATOM` and `atom` are the same). - * * A format file matching the given format name must exist in the working * directory! * @@ -118,6 +122,7 @@ public function getFormatNames(){ * valid, null otherwise. */ protected function sanitizeFormatName($name) { + $name = ucfirst($name); if(is_string($name)) { @@ -131,18 +136,12 @@ protected function sanitizeFormatName($name) { $name = $matches[1]; } - // Improve performance for correctly written format names + // The name is valid if a corresponding format file is found on disk if(in_array($name, $this->getFormatNames())) { $index = array_search($name, $this->getFormatNames()); return $this->getFormatNames()[$index]; } - // The name is valid if a corresponding format file is found on disk - if(in_array(strtolower($name), array_map('strtolower', $this->getFormatNames()))) { - $index = array_search(strtolower($name), array_map('strtolower', $this->getFormatNames())); - return $this->getFormatNames()[$index]; - } - Debug::log('Invalid format name: "' . $name . '"!'); } From cd4f6742dab1c624874aeeaa7506f07d4d919132 Mon Sep 17 00:00:00 2001 From: Eugene Molotov Date: Tue, 9 Feb 2021 18:10:04 +0500 Subject: [PATCH 2/2] Update FormatFactory.php --- lib/FormatFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/FormatFactory.php b/lib/FormatFactory.php index 017a19216a8..e2bba2fc577 100644 --- a/lib/FormatFactory.php +++ b/lib/FormatFactory.php @@ -122,7 +122,7 @@ public function getFormatNames(){ * valid, null otherwise. */ protected function sanitizeFormatName($name) { - $name = ucfirst($name); + $name = ucfirst(strtolower($name)); if(is_string($name)) {