From f334d51b1729d9653f0094e8db5f00e30f5d8389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 2 Dec 2021 10:02:49 +0100 Subject: [PATCH 1/3] Bump scssphp/scssphp to 1.8.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- 3rdparty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty b/3rdparty index 1269091e96a2a..108a384f119a8 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit 1269091e96a2a550912db37c0d2b29ed5c0aa60f +Subproject commit 108a384f119a8bdad65210e7231a287f46ede73e From 324e0dc36ca1781de27fe30453e30c460cc3dfb4 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Thu, 2 Dec 2021 11:53:34 +0100 Subject: [PATCH 2/3] Add rgb to hsl converter This ports away from using now internal functions from scssphp. Signed-off-by: Carl Schwan --- apps/theming/lib/Util.php | 45 +++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/apps/theming/lib/Util.php b/apps/theming/lib/Util.php index 70b5a00f9ea2d..f18194c32667a 100644 --- a/apps/theming/lib/Util.php +++ b/apps/theming/lib/Util.php @@ -34,7 +34,6 @@ use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFile; use OCP\IConfig; -use ScssPhp\ScssPhp\Compiler; class Util { @@ -96,15 +95,53 @@ public function elementColor($color, bool $brightBackground = true) { return $color; } + /** + * Convert RGB to HSL + * + * Copied from cssphp, copyright Leaf Corcoran, licensed under MIT + * + * @param integer $red + * @param integer $green + * @param integer $blue + * + * @return array + */ + public function toHSL($red, $green, $blue) + { + $min = min($red, $green, $blue); + $max = max($red, $green, $blue); + $l = $min + $max; + $d = $max - $min; + + if ((int) $d === 0) { + $h = $s = 0; + } else { + if ($l < 255) { + $s = $d / $l; + } else { + $s = $d / (510 - $l); + } + + if ($red == $max) { + $h = 60 * ($green - $blue) / $d; + } elseif ($green == $max) { + $h = 60 * ($blue - $red) / $d + 120; + } elseif ($blue == $max) { + $h = 60 * ($red - $green) / $d + 240; + } + } + + return [fmod($h, 360), $s * 100, $l / 5.1]; + } + /** * @param string $color rgb color value * @return float */ public function calculateLuminance($color) { [$red, $green, $blue] = $this->hexToRGB($color); - $compiler = new Compiler(); - $hsl = $compiler->toHSL($red, $green, $blue); - return $hsl[3] / 100; + $hsl = $this->toHSL($red, $green, $blue); + return $hsl[2] / 100; } /** From dfb569f097119ac8b5722607a86cc77e97bff3af Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Thu, 2 Dec 2021 12:01:01 +0100 Subject: [PATCH 3/3] Follow upstream security recommandation See https://scssphp.github.io/scssphp/docs/#security-considerations Signed-off-by: Carl Schwan --- apps/theming/lib/Util.php | 7 +++---- build/psalm-baseline.xml | 3 --- lib/private/Template/SCSSCacher.php | 5 ++--- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/apps/theming/lib/Util.php b/apps/theming/lib/Util.php index f18194c32667a..208cd42934eb2 100644 --- a/apps/theming/lib/Util.php +++ b/apps/theming/lib/Util.php @@ -106,15 +106,14 @@ public function elementColor($color, bool $brightBackground = true) { * * @return array */ - public function toHSL($red, $green, $blue) - { + public function toHSL($red, $green, $blue) { $min = min($red, $green, $blue); $max = max($red, $green, $blue); $l = $min + $max; $d = $max - $min; if ((int) $d === 0) { - $h = $s = 0; + $h = $s = 0; } else { if ($l < 255) { $s = $d / $l; @@ -126,7 +125,7 @@ public function toHSL($red, $green, $blue) $h = 60 * ($green - $blue) / $d; } elseif ($green == $max) { $h = 60 * ($blue - $red) / $d + 120; - } elseif ($blue == $max) { + } else { $h = 60 * ($red - $green) / $d + 240; } } diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index cca3cbd2b54b3..fdc177ffac8b6 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -345,9 +345,6 @@ - - null|string - array diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index 0543427f99796..536557e7a3dc9 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -45,7 +45,6 @@ use OCP\IMemcache; use OCP\IURLGenerator; use ScssPhp\ScssPhp\Compiler; -use ScssPhp\ScssPhp\Exception\ParserException; use ScssPhp\ScssPhp\OutputStyle; class SCSSCacher { @@ -340,7 +339,7 @@ private function cache(string $path, string $fileNameCSS, string $fileNameSCSS, '@import "variables.scss";' . '@import "functions.scss";' . '@import "' . $fileNameSCSS . '";'); - } catch (ParserException $e) { + } catch (\Exception $e) { $this->logger->logException($e, ['app' => 'scss_cacher']); return false; @@ -431,7 +430,7 @@ private function getInjectedVariables(string $cache = ''): string { $scss = new Compiler(); $scss->compile($variables); $this->injectedVariables = $variables; - } catch (ParserException $e) { + } catch (\Exception $e) { $this->logger->logException($e, ['app' => 'scss_cacher']); }