Skip to content

Commit a670060

Browse files
authored
Merge pull request #7540 from nextcloud/backport/7510/stable31
[stable31] Fix/display labels with invalid colors
2 parents da467e9 + 1e96ca3 commit a670060

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎lib/Validators/LabelServiceValidator.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
namespace OCA\Deck\Validators;
1111

1212
class LabelServiceValidator extends BaseValidator {
13+
protected function hex_color(string $value): bool {
14+
return preg_match('/[A-Fa-f0-9]{6}/', $value) === 1;
15+
}
16+
1317
public function rules() {
1418
return [
1519
'id' => ['numeric'],
1620
'title' => ['not_empty', 'not_null', 'not_false', 'max:100'],
1721
'boardId' => ['numeric', 'not_null'],
18-
'color' => ['not_empty', 'not_null', 'not_false', 'max:6']
22+
'color' => ['not_empty', 'not_null', 'not_false', 'max:6', 'hex_color']
1923
];
2024
}
2125
}

‎src/mixins/color.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6+
import { isDarkTheme } from '@nextcloud/vue'
67
import chroma from 'chroma-js'
78

89
export default {
910
methods: {
1011
textColor(hex) {
12+
if (!this.colorIsValid(hex)) {
13+
return isDarkTheme ? '#ffffff' : '#000000'
14+
}
1115
return chroma(hex ?? 'ffffff').get('lab.l') > 50 ? '#000000' : '#ffffff'
1216
},
1317
colorIsValid(hex) {

0 commit comments

Comments
 (0)