diff --git a/package-lock.json b/package-lock.json index a09cb491..90d8e3e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7031,6 +7031,12 @@ "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==", "dev": true }, + "validate-color": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/validate-color/-/validate-color-2.2.1.tgz", + "integrity": "sha512-1eDb1zqP6W6bbfKKl6dRXObelNoQpW7aF3BUTh2AivWuhcD0pa3ejwURWqrVsyKJMLBMlHLFcM3sj5J+dSFhbg==", + "dev": true + }, "validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", diff --git a/package.json b/package.json index e97878e1..f062477c 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "svgo": "^2.8.0", "ts-loader": "^8.3.0", "typescript": "^4.3.5", + "validate-color": "^2.2.1", "webpack": "^4.46.0", "webpack-cli": "^3.3.12" }, diff --git a/shared/lib/autocolors.ts b/shared/lib/autocolors.ts index d4552a96..e29cd955 100644 --- a/shared/lib/autocolors.ts +++ b/shared/lib/autocolors.ts @@ -1,4 +1,5 @@ import type { ChatType } from './types' +const validateColor = require('validate-color').default type AutoColorValue = string @@ -38,12 +39,7 @@ function areAutoColorsValid (autocolors: AutoColors): true | string[] { for (const k in autocolors) { const color = autocolors[k as keyof AutoColors] // FIXME: there are missing cases. For now there are only basic values formats. - if ( - !/^rgb\(\d{1,3},\s*\d{1,3},\s*\d{1,3}\)$/.test(color) && - !/^rgba\(\d{1,3},\s*\d{1,3},\s*\d{1,3},\s*(1|0|0?.\d+)\)$/.test(color) && - !/^#[0-9a-fA-F]{3,6}$/.test(color) && - !/^[a-z]+$/ - ) { + if (!validateColor(color)) { errors.push(color) } }