{"record":{"id":"5ff6c24b58d8afff","repo":"siyuan-note/siyuan","slug":"color-s-must-use-rrggbb-format","errorCode":null,"errorMessage":"color [%s] must use #RRGGBB format","messagePattern":"color \\[(.+?)\\] must use #RRGGBB format","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":870,"sourceCode":"\nfunc normalizeInlineStyleTheme(theme *InlineStyleTheme) (ret *InlineStyleTheme, err error) {\n\tret = &InlineStyleTheme{}\n\tif ret.Color, err = normalizeInlineStyleColor(theme.Color); err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid color: %w\", err)\n\t}\n\tif ret.BackgroundColor, err = normalizeInlineStyleColor(theme.BackgroundColor); err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid backgroundColor: %w\", err)\n\t}\n\treturn ret, nil\n}\n\nfunc normalizeInlineStyleColor(color string) (ret string, err error) {\n\tret = strings.ToLower(strings.TrimSpace(color))\n\tif ret == \"\" {\n\t\treturn ret, nil\n\t}\n\tif !inlineStyleColorPattern.MatchString(ret) {\n\t\treturn \"\", fmt.Errorf(\"color [%s] must use #RRGGBB format\", color)\n\t}\n\treturn ret, nil\n}\n\nfunc init() {\n\tav.LoadWorkspacePalette = loadWorkspaceAVPalette\n}\n\nfunc loadWorkspaceAVPalette() (colors []*av.AttributeViewCustomColor, order []string) {\n\twaitForSyncingStorages()\n\tinlineStylesLock.Lock()\n\tdefer inlineStylesLock.Unlock()\n\tif workspaceAVPaletteCache == nil || workspaceAVPaletteCachePath != inlineStylesPath() {\n\t\tstyles, err := loadInlineStyles()\n\t\tif err != nil {\n\t\t\treturn nil, nil\n\t\t}\n\t\tcacheWorkspaceAVPalette(styles.AV)","sourceCodeStart":852,"sourceCodeEnd":888,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/inline_style.go#L852-L888","documentation":"normalizeInlineStyleColor trims and lowercases the input, allows an empty string, and otherwise requires an exact match of the inlineStyleColorPattern — a 6-digit hex color in #RRGGBB form. Anything else (3-digit hex, named colors, rgb(), missing #, wrong length) fails with this message showing the original input.","triggerScenarios":"Any theme save where Color or BackgroundColor is a non-empty string not matching ^#[0-9a-f]{6}$ (after trim/lowercase), raised at the normalizeInlineStyleColor call in kernel/model/inline_style.go.","commonSituations":"Users pasting colors from design tools as rgb()/hsl(); shorthand #fff values; uppercase #AABBCC is fine (lowercased) but 5- or 7-character typos are not; HTML attribute values like \"#AABBCC;\" with trailing semicolons.","solutions":["Normalize the value to exactly 7 characters: '#', then 6 lowercase hex digits (e.g. #1e90ff).","Expand #RGB shorthand to #RRGGBB and strip any trailing ';' or whitespace.","Test the value against the regex /^#[0-9a-fA-F]{6}$/ client-side before submitting."],"exampleFix":"// before\ncolor = \"#fff\";\nsaveTheme(color);\n// after\ncolor = \"#ffffff\";\nif (!/^#[0-9a-fA-F]{6}$/.test(color)) throw new Error(\"bad color\");\nsaveTheme(color);","handlingStrategy":"validation","validationCode":"function toHexColor(input) {\n  const s = String(input).trim().toLowerCase();\n  if (s === \"\") return \"\";\n  const m = /^#([0-9a-f]{6})$/.exec(s) || /^#([0-9a-f])([0-9a-f])([0-9a-f])$/.exec(s);\n  if (!m) throw new Error(`color [${input}] must use #RRGGBB format`);\n  return m.length === 4 ? \"#\" + m[1] + m[2] + m[3] : s;\n}","typeGuard":null,"tryCatchPattern":"try {\n  saveInlineStyleTheme(theme);\n} catch (e) {\n  if (String(e.message).includes(\"must use #RRGGBB format\")) {\n    // re-prompt for a valid hex color\n  } else { throw e; }\n}","preventionTips":["Always run the #RRGGBB regex check client-side before submission.","Expand 3-digit hex and strip whitespace/semicolons from pasted values.","Use a hex-only color picker rather than free-text input."],"tags":["validation","regex","color-format"],"backgroundTag":"invalid-argument-format","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}