1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-24 21:15:51 +01:00

fix: incorrect primary_color crash the ui (#1771)

* fix: incorrect primary_color crash the ui

* chore: also supports 3 and 6 characters as valid hex
This commit is contained in:
Juan Picado @jotadeveloper 2020-04-09 00:33:03 +02:00 committed by GitHub
parent 4a812620cf
commit d68926050d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -34,6 +34,15 @@ export function loadTheme(config) {
}
}
export function validatePrimaryColor(primaryColor) {
const isHex = /^#+([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/i.test(primaryColor);
if (!isHex) {
return '';
}
return primaryColor;
}
const sendFileCallback = next => err => {
if (!err) {
return;
@ -84,7 +93,7 @@ export default function(config, auth, storage) {
const base = combineBaseUrl(protocol, host, url_prefix);
const language = config?.i18n?.web ?? DEFAULT_LANGUAGE;
const darkMode = config?.web?.darkMode ?? false;
const primaryColor = _.get(config, 'web.primary_color') ? config.web.primary_color : '';
const primaryColor = validatePrimaryColor(config?.web?.primary_color);
const title = _.get(config, 'web.title') ? config.web.title : WEB_TITLE;
const scope = _.get(config, 'web.scope') ? config.web.scope : '';
const options = {