diff --git a/lib/Validators/LabelServiceValidator.php b/lib/Validators/LabelServiceValidator.php index 7ccbb57d2..720994bce 100644 --- a/lib/Validators/LabelServiceValidator.php +++ b/lib/Validators/LabelServiceValidator.php @@ -10,12 +10,16 @@ namespace OCA\Deck\Validators; class LabelServiceValidator extends BaseValidator { + protected function hex_color(string $value): bool { + return preg_match('/[A-Fa-f0-9]{6}/', $value) === 1; + } + public function rules() { return [ 'id' => ['numeric'], 'title' => ['not_empty', 'not_null', 'not_false', 'max:100'], 'boardId' => ['numeric', 'not_null'], - 'color' => ['not_empty', 'not_null', 'not_false', 'max:6'] + 'color' => ['not_empty', 'not_null', 'not_false', 'max:6', 'hex_color'] ]; } } diff --git a/src/mixins/color.js b/src/mixins/color.js index e3bf94bb3..88ee62d35 100644 --- a/src/mixins/color.js +++ b/src/mixins/color.js @@ -3,11 +3,15 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ +import { isDarkTheme } from '@nextcloud/vue' import chroma from 'chroma-js' export default { methods: { textColor(hex) { + if (!this.colorIsValid(hex)) { + return isDarkTheme ? '#ffffff' : '#000000' + } return chroma(hex ?? 'ffffff').get('lab.l') > 50 ? '#000000' : '#ffffff' }, colorIsValid(hex) {