From 324fdf8986f6ab1a11047d8bf24e00781d67bcf2 Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Tue, 4 Aug 2020 14:52:35 +0200 Subject: [PATCH] Add basic validation for StyleGlobalValuesForm --- .../files/acp/templates/styleGlobalValues.tpl | 7 ++++- .../acp/form/StyleGlobalValuesForm.class.php | 29 +++++++++++++++++++ .../lib/system/style/StyleCompiler.class.php | 15 ++++++++-- wcfsetup/install/lang/de.xml | 1 + wcfsetup/install/lang/en.xml | 1 + 5 files changed, 50 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/styleGlobalValues.tpl b/wcfsetup/install/files/acp/templates/styleGlobalValues.tpl index 51e53478cb..aa087b1a15 100644 --- a/wcfsetup/install/files/acp/templates/styleGlobalValues.tpl +++ b/wcfsetup/install/files/acp/templates/styleGlobalValues.tpl @@ -22,7 +22,7 @@ {/if}
-
+
{lang}wcf.acp.style.globalValues.input{/lang}
@@ -31,6 +31,11 @@
+ {if $errorField == 'styles'} + + {lang}wcf.acp.style.globalValues.input.error{/lang} + + {/if} {include file='codemirror' codemirrorMode='text/x-less' codemirrorSelector='#styles'}
diff --git a/wcfsetup/install/files/lib/acp/form/StyleGlobalValuesForm.class.php b/wcfsetup/install/files/lib/acp/form/StyleGlobalValuesForm.class.php index a86b2b551e..e7c34efe11 100644 --- a/wcfsetup/install/files/lib/acp/form/StyleGlobalValuesForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/StyleGlobalValuesForm.class.php @@ -1,10 +1,12 @@ styles); + + try { + // Due to performance issues we can only compile the default style and check, + // whether there are syntax issues. + $defaultStyle = StyleHandler::getInstance()->getDefaultStyle(); + $errorMessage = StyleCompiler::getInstance()->testStyle($defaultStyle->apiVersion, $defaultStyle->imagePath, $defaultStyle->getVariables(), $tmpFile); + + if ($errorMessage !== true) { + throw new UserInputException('styles', [ + 'message' => $errorMessage, + ]); + } + } + finally { + unlink($tmpFile); + } + + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php b/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php index 810dcc4248..6868a9904f 100644 --- a/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php +++ b/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php @@ -98,10 +98,11 @@ class StyleCompiler extends SingletonFactory { * @param string $apiVersion * @param string $imagePath * @param string[] $variables + * @param string|null $customCustomSCSSFile * @return bool|string * @since 5.3 */ - public function testStyle($apiVersion, $imagePath, array $variables) { + public function testStyle($apiVersion, $imagePath, array $variables, $customCustomSCSSFile = null) { $individualScss = ''; if (isset($variables['individualScss'])) { $individualScss = $variables['individualScss']; @@ -135,9 +136,19 @@ class StyleCompiler extends SingletonFactory { $parameters = ['scss' => '']; EventHandler::getInstance()->fireAction($this, 'compile', $parameters); + $files = $this->getFiles(); + + if ($customCustomSCSSFile !== null) { + if (($customSCSSFileKey = array_search(WCF_DIR . self::FILE_GLOBAL_VALUES, $files)) !== false) { + unset($files[$customSCSSFileKey]); + } + + $files[] = $customCustomSCSSFile; + } + try { $this->compileStylesheetToString( - $this->getFiles(), + $files, $variables, $individualScss . (!empty($parameters['scss']) ? "\n" . $parameters['scss'] : ''), function($content) { diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index b99a93427b..ba830060cb 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -2905,6 +2905,7 @@ Kein Abschnitt darf leer sein und alle Abschnitten dürfen nur folgende Zeichen + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 218dabaef5..5efdb4b878 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -2833,6 +2833,7 @@ If you have already bought the licenses for the listed apps, th + -- 2.20.1