Skip to content

Commit b803d82

Browse files
committed
pkp/pkp-lib#11974 Validate default plugin base colour setting value
1 parent 7ef0eb7 commit b803d82

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

plugins/themes/default/DefaultThemePlugin.inc.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ public function init() {
129129
}
130130

131131
// Update colour based on theme option
132-
if ($this->getOption('baseColour') !== '#1E6292') {
133-
$additionalLessVariables[] = '@bg-base:' . $this->getOption('baseColour') . ';';
134-
if (!$this->isColourDark($this->getOption('baseColour'))) {
132+
if (($baseColour = $this->getOption('baseColour')) !== '#1E6292') {
133+
if (!preg_match('/^#[0-9a-fA-F]{1,6}$/', $baseColour)) $baseColour = '#1E6292'; // pkp/pkp-lib#11974
134+
$additionalLessVariables[] = '@bg-base:' . $baseColour . ';';
135+
if (!$this->isColourDark($baseColour)) {
135136
$additionalLessVariables[] = '@text-bg-base:rgba(0,0,0,0.84);';
136137
$additionalLessVariables[] = '@bg-base-border-color:rgba(0,0,0,0.2);';
137138
}
@@ -199,6 +200,14 @@ function getContextSpecificPluginSettingsFile() {
199200
return $this->getPluginPath() . '/settings.xml';
200201
}
201202

203+
/** @see ThemePlugin::saveOption */
204+
public function saveOption($name, $value, $contextId = null) {
205+
// Validate the base colour setting value.
206+
if ($name == 'baseColour' && !preg_match('/^#[0-9a-fA-F]{1,6}$/', $value)) $value = null; // pkp/pkp-lib#11974
207+
208+
parent::saveOption($name, $value, $contextId);
209+
}
210+
202211
/**
203212
* Get the name of the settings file to be installed site-wide when
204213
* OJS is installed.

0 commit comments

Comments
 (0)