Skip to content

Commit

Permalink
fix: incorrect primary_color crash the ui (#1771)
Browse files Browse the repository at this point in the history
* fix: incorrect primary_color crash the ui

* chore: also supports 3 and 6 characters as valid hex
  • Loading branch information
juanpicado committed Apr 8, 2020
1 parent 4a81262 commit d689260
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/api/web/index.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit d689260

Please sign in to comment.