{"record":{"id":"4bee7e8e3d3fa683","repo":"BigPizzaV3/CodexPlusPlus","slug":"theme-css-4bee7e","errorCode":null,"errorMessage":"theme.css 规则数量超过限制","messagePattern":"theme\\.css 规则数量超过限制","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/dream_skin_package.rs","lineNumber":382,"sourceCode":"            {\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        }\n        rest = &rest[close + 1..];\n    }\n    if parsed.is_empty() {\n        bail!(\"theme.css 必须至少包含一条规则\");\n    }\n    Ok(parsed)\n}\n\nfn forbidden_css_character(character: char) -> bool {\n    matches!(\n        character as u32,\n        0x0000..=0x0008 | 0x000b | 0x000e..=0x001f | 0x007f..=0x009f\n            | 0x2028 | 0x2029 | 0x200e | 0x200f | 0x202a..=0x202e | 0x2066..=0x2069 | 0xfeff\n    )\n}\n\nfn validate_property_value(property: &str, value: &str) -> bool {","sourceCodeStart":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/dream_skin_package.rs#L364-L400","documentation":"parse_safe_css enforces a hard cap of 128 CSS rules when parsing a Dream Skin theme package's theme.css. After each rule is pushed, if the count exceeds 128 the parser bails with this message. This limits resource usage and attack surface of third-party skin CSS.","triggerScenarios":"Calling validate_safe_css or compile_safe_css (directly or via validate_and_read_package) with a theme.css containing more than 128 rules (i.e. the 129th closing brace is parsed and parsed.len() becomes 129 > 128).","commonSituations":"Authors exporting a full site theme or a large design-system stylesheet into a skin package; hand-editing theme.css by adding many selectors; automated CSS dump from a build tool pasted into theme.css.","solutions":["Reduce the number of rules in theme.css to 128 or fewer by merging selectors that share declarations.","Split the theme into multiple skin packages or drop non-essential parts.","Generate a rule-count report before packaging and trim the largest rule groups."],"exampleFix":"/* before: 130 rules like */\n.ds-part[\"header\"] { color: #111; }\n.ds-part[\"footer\"] { color: #111; }\n/* ... x130 */\n/* after: merge selectors sharing declarations */\n.ds-part[\"header\"], .ds-part[\"footer\"] { color: #111; }","handlingStrategy":"validation","validationCode":"fn rule_count_ok(css: &str) -> bool {\n    css.match_indices('}').count() <= 128\n}\nif !rule_count_ok(&theme_css) { /* trim rules before validating */ }","typeGuard":null,"tryCatchPattern":"match validate_safe_css(&css) {\n    Ok(rules) => apply(rules),\n    Err(e) if e.to_string().contains(\"规则数量超过限制\") => eprintln!(\"trim theme.css to <= 128 rules\"),\n    Err(e) => return Err(e),\n}","preventionTips":["Count selectors/rules at build time before packaging.","Merge selectors sharing identical declarations.","Keep themes modular and small."],"tags":["css","validation","limit-exceeded"],"backgroundTag":"value-out-of-range","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"}