BigPizzaV3/CodexPlusPlus · error

theme.css 属性值不受 Safe CSS 支持:

Error message

theme.css 属性值不受 Safe CSS 支持:{property}

What it means

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}'.

Solutions

  1. Convert values to supported forms: hex (#rgb/#rgba/#rrggbb/#rrggbbaa), rgb()/rgba(), currentcolor, transparent (non-color props), or registered --ds-theme-color-* vars
  2. 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))
  3. Replace gradients/url()/calc()/named colors with flat colors; limit font-family to the generic whitelist (system-ui, sans-serif, serif, monospace, etc.)
  4. Remove '!', ';', '<', '>', '{', '}' from values

Example fix

// before
[data-ds-part="main"] { background-color: linear-gradient(red, blue); font-size: 2rem; }
// after
[data-ds-part="main"] { background-color: #101418; font-size: 16px; }
Defensive patterns

Strategy: validation

Validate before calling

fn value_chars_ok(value: &str) -> bool {
    !value.is_empty()
        && value.chars().count() <= 512
        && !value.contains(['{', '}', '<', '>', '!', ';'])
}
// additionally check per-property forms: colors = hex/rgb()/rgba()/var(--ds-theme-color-*)/currentcolor;
// sizes = px in range; font-weight in {400,500,600,700,normal,bold}; fonts from generic whitelist.

Try / catch

match validate_safe_css(&css) {
    Err(e) if e.to_string().contains("不受 Safe CSS 支持") => Err("convert values to the whitelisted forms (hex colors, px ranges, registered vars)".into()),
    other => other,
}

Prevention

When it happens

Trigger: `!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.

Common situations: 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).

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/afc6c254f5f1db97. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/dream_skin_package.rs:365

            let (property, value) = declaration
                .split_once(':')
                .context("theme.css 声明语法无效")?;
            let property = property.trim();
            let value = value.trim();
            if !property
                .bytes()
                .enumerate()
                .all(|(index, byte)| byte.is_ascii_lowercase() || (index > 0 && byte == b'-'))
                || !seen.insert(property)
            {
                bail!("theme.css CSS 属性无效或重复:{property}");
            }
            if value.is_empty()
                || value.chars().count() > 512
                || value.contains(['{', '}', '<', '>', '!', ';'])
                || !validate_property_value(property, value)
            {
                bail!("theme.css 属性值不受 Safe CSS 支持:{property}");
            }
            declarations += 1;
            if declarations > 512 {
                bail!("theme.css 声明数量超过限制");
            }
            rule_declarations.push((property, value));
        }
        if rule_declarations.is_empty() {
            bail!("theme.css 每条规则必须至少包含一个声明");
        }
        parsed.push(SafeCssRule {
            selector,
            part,
            declarations: rule_declarations,
        });
        if parsed.len() > 128 {
            bail!("theme.css 规则数量超过限制");
        }

View on GitHub (pinned to b1ed92e5e4)