{"record":{"id":"7317c6b0197534b2","repo":"BigPizzaV3/CodexPlusPlus","slug":"theme-css-7317c6","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":369,"sourceCode":"            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        }\n        rest = &rest[close + 1..];\n    }\n    if parsed.is_empty() {\n        bail!(\"theme.css 必须至少包含一条规则\");","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/dream_skin_package.rs#L351-L387","documentation":"parse_safe_css enforces a global budget of 512 declarations across the whole stylesheet: after each accepted declaration it increments the counter and bails with 'theme.css 声明数量超过限制' once the count exceeds 512. This bounds the compiled @layer dreamskin-community output and prevents resource exhaustion from huge packages.","triggerScenarios":"validate_safe_css/compile_safe_css on a theme.css containing more than 512 `prop: value;` declarations in total (across all rules and pseudo-state variants).","commonSituations":"Generated themes enumerating every part × state × property combination; machine-generated CSS from design tools with exhaustive variable expansions; concatenated multi-theme stylesheets.","solutions":["Count declarations (`grep -c ';' theme.css`-ish) and prune to ≤ 512 by deleting rules for less-important parts","Merge duplicate rules and drop redundant declarations (e.g. per-side border-color where border-color suffices)","Split styling across multiple theme packages if more coverage is genuinely needed"],"exampleFix":"// before: 128 rules × 8 declarations = 1024 declarations\n// after: keep the 60 highest-impact rules → ~480 declarations","handlingStrategy":"validation","validationCode":"fn declaration_count(css: &str) -> usize {\n    css.split(['{', '}']).skip(1).step_by(2).map(|body| body.split(';').filter(|d| !d.trim().is_empty()).count()).sum()\n}\nassert!(declaration_count(&css) <= 512, \"too many declarations\");","typeGuard":null,"tryCatchPattern":"if declaration_count(&css) > 512 {\n    return Err(\"reduce theme.css to at most 512 declarations\".into());\n}\nlet _ = validate_safe_css(&css)?;","preventionTips":["Count `prop: value;` occurrences before packaging; stay at or below 512 total","Prefer border-color over per-side duplicates; merge same-part rules","Avoid machine-generated exhaustive styling; curate the highest-impact rules"],"tags":["css","limits","resource-exhaustion"],"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"}