{"record":{"id":"afc6c254f5f1db97","repo":"BigPizzaV3/CodexPlusPlus","slug":"theme-css-safe-css-property","errorCode":null,"errorMessage":"theme.css 属性值不受 Safe CSS 支持：{property}","messagePattern":"theme\\.css 属性值不受 Safe CSS 支持：(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/dream_skin_package.rs","lineNumber":365,"sourceCode":"            let (property, value) = declaration\n                .split_once(':')\n                .context(\"theme.css 声明语法无效\")?;\n            let property = property.trim();\n            let value = value.trim();\n            if !property\n                .bytes()\n                .enumerate()\n                .all(|(index, byte)| byte.is_ascii_lowercase() || (index > 0 && byte == b'-'))\n                || !seen.insert(property)\n            {\n                bail!(\"theme.css CSS 属性无效或重复：{property}\");\n            }\n            if value.is_empty()\n                || value.chars().count() > 512\n                || value.contains(['{', '}', '<', '>', '!', ';'])\n                || !validate_property_value(property, value)\n            {\n                bail!(\"theme.css 属性值不受 Safe CSS 支持：{property}\");\n            }\n            declarations += 1;\n            if declarations > 512 {\n                bail!(\"theme.css 声明数量超过限制\");\n            }\n            rule_declarations.push((property, value));\n        }\n        if rule_declarations.is_empty() {\n            bail!(\"theme.css 每条规则必须至少包含一个声明\");\n        }\n        parsed.push(SafeCssRule {\n            selector,\n            part,\n            declarations: rule_declarations,\n        });\n        if parsed.len() > 128 {\n            bail!(\"theme.css 规则数量超过限制\");\n        }","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/dream_skin_package.rs#L347-L383","documentation":"For every declaration, parse_safe_css rejects the value if it is empty, longer than 512 chars, contains '{', '}', '<', '>', '!' or ';', or fails validate_property_value — a strict per-property whitelist (hex/rgb/registered --ds-theme-* vars for colors, px ranges for widths/radii/gaps, enumerated keywords for border-style/font-weight, bounded numerics for font-size/opacity/etc.). Failure bails with 'theme.css 属性值不受 Safe CSS 支持：{property}'.","triggerScenarios":"`!important` or ';' inside a value; named colors like `red` or `hsl(...)`; url(), gradients (linear-gradient), calc(), rem/em/% units; font-family with custom font names; font-size outside 12-20px; opacity below 0.65; box-shadow spread beyond ±48px; unregistered var() names.","commonSituations":"Porting normal web CSS (gradients, rem units, HSL) into the restricted format; using design tokens not among the registered --ds-theme-* variables; fat-fingered ranges (font-size: 24px, gap: 2rem).","solutions":["Convert values to supported forms: hex (#rgb/#rgba/#rrggbb/#rrggbbaa), rgb()/rgba(), currentcolor, transparent (non-color props), or registered --ds-theme-color-* vars","Use px-only numeric values within each property's range (e.g. font-size 12-20px, gap 0-24px, opacity 0.65-1.0 or var(--ds-theme-surface-opacity))","Replace gradients/url()/calc()/named colors with flat colors; limit font-family to the generic whitelist (system-ui, sans-serif, serif, monospace, etc.)","Remove '!', ';', '<', '>', '{', '}' from values"],"exampleFix":"// before\n[data-ds-part=\"main\"] { background-color: linear-gradient(red, blue); font-size: 2rem; }\n// after\n[data-ds-part=\"main\"] { background-color: #101418; font-size: 16px; }","handlingStrategy":"validation","validationCode":"fn value_chars_ok(value: &str) -> bool {\n    !value.is_empty()\n        && value.chars().count() <= 512\n        && !value.contains(['{', '}', '<', '>', '!', ';'])\n}\n// additionally check per-property forms: colors = hex/rgb()/rgba()/var(--ds-theme-color-*)/currentcolor;\n// sizes = px in range; font-weight in {400,500,600,700,normal,bold}; fonts from generic whitelist.","typeGuard":null,"tryCatchPattern":"match validate_safe_css(&css) {\n    Err(e) if e.to_string().contains(\"不受 Safe CSS 支持\") => Err(\"convert values to the whitelisted forms (hex colors, px ranges, registered vars)\".into()),\n    other => other,\n}","preventionTips":["Use only hex/rgb()/rgba()/currentcolor/transparent/registered --ds-theme-color-* vars for colors","Use px units only and respect each property's numeric range (font-size 12-20px, gap 0-24px, opacity >= 0.65)","No url(), gradients, calc(), rem/em/%, hsl(), !important, or custom font names"],"tags":["css","property-values","whitelist"],"backgroundTag":"invalid-argument-value","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}