Skip to content
Snippets Groups Projects
Commit 1f0cc708 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

disable warnings for less compilation and sanitize inputs, fixes #1211

Closes #1211

Merge request studip/studip!722
parent a8550b59
No related branches found
No related tags found
No related merge requests found
...@@ -48,22 +48,33 @@ class LESSCompiler implements Compiler ...@@ -48,22 +48,33 @@ class LESSCompiler implements Compiler
* and variables for Stud.IP so almost all mixins and variables of the * and variables for Stud.IP so almost all mixins and variables of the
* core system can be used. This includes colors and icons. * core system can be used. This includes colors and icons.
* *
* @param String $less LESS content to compile * @param string $input LESS content to compile
* @param Array $variables Additional variables for the LESS compilation * @param array $variables Additional variables for the LESS compilation
* @return String containing the generated CSS * @return string containing the generated CSS
*/ */
public function compile($input, array $variables = []) public function compile($input, array $variables = []): string
{ {
$less = $this->getPrefix() . $input; $less = $this->getPrefix() . $input;
$variables['image-path'] = '"' . Assets::url('images') . '"'; $variables['image-path'] = '"' . Assets::url('images') . '"';
// Disable warnings since we currently have no other means to get rid
// of them
// TODO: Look again into this (2022-06-23)
$error_reporting = error_reporting();
error_reporting($error_reporting & ~E_WARNING);
$parser = new Parser(['strictMath' => true], null, [ $parser = new Parser(['strictMath' => true], null, [
new FileSystemImporter(["{$GLOBALS['STUDIP_BASE_PATH']}/resources/"]) new FileSystemImporter(["{$GLOBALS['STUDIP_BASE_PATH']}/resources/"])
]); ]);
$parser->setVariables($variables); $parser->setVariables($variables);
$parser->parseString($less); $parser->parseString($less);
return $parser->getCSS(); $css = $parser->getCSS();
// Restore error reporting
error_reporting($error_reporting);
return $css;
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment