BigPizzaV3/CodexPlusPlus · error

theme.css 包含不允许的控制字符、注释或转义

Error message

theme.css 包含不允许的控制字符、注释或转义

What it means

Before structural parsing, parse_safe_css scans theme.css for characters forbidden by forbidden_css_character (C0 controls except tab/newline/CR, C1 controls, BOM, line/paragraph separators, bidi overrides) and for the literal sequences '/*', '*/' or any backslash. Any hit means the stylesheet contains comments, escapes or invisible/control characters that could smuggle parser-differential attacks, so it bails with 'theme.css 包含不允许的控制字符、注释或转义'.

Solutions

  1. Strip all /* */ comments and remove any backslash characters from theme.css
  2. Save the file as UTF-8 without BOM and run a sanitizer that deletes U+0000-0008, U+000B, U+000E-001F, U+007F-009F, U+200E/200F, U+202A-202E, U+2066-2069, U+2028/2029, U+FEFF
  3. Re-export text through a normalizer that removes zero-width/bidi characters, then re-run validate_safe_css

Example fix

// before
/* main colors */
[data-ds-part="main"] { color: #fff\; }
// after
[data-ds-part="main"] { color: #ffffff; }
Defensive patterns

Strategy: validation

Validate before calling

fn css_has_no_forbidden_chars(css: &str) -> bool {
    !css.contains("/*") && !css.contains("*/") && !css.contains('\\')
        && !css.chars().any(|c| matches!(c as u32, 0x0..=0x8 | 0xb | 0xe..=0x1f | 0x7f..=0x9f | 0x2028 | 0x2029 | 0x200e | 0x200f | 0x202a..=0x202e | 0x2066..=0x2069 | 0xfeff))
}

Try / catch

match validate_safe_css(&css) {
    Err(e) if e.to_string().contains("控制字符、注释或转义") => {
        let cleaned = strip_comments_bom_and_control_chars(&css);
        validate_safe_css(&cleaned)?
    }
    other => other?,
}

Prevention

When it happens

Trigger: theme.css containing /* ... */ comments; a backslash escape like \: or content strings; a UTF-8 BOM at file start (0xFEFF); invisible bidi marks (U+200E/200F, U+202A-202E, U+2066-2069) or U+2028/2029 pasted from web pages; control characters such as NUL or vertical tab.

Common situations: CSS copied from tutorials or minifiers that keep comments; editors saving with BOM; copy-pasting theme names/labels containing zero-width or RTL marks; template engines injecting escape sequences.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

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

}

#[derive(Debug)]
struct SafeCssRule<'a> {
    selector: &'a str,
    part: &'a str,
    declarations: Vec<(&'a str, &'a str)>,
}

fn parse_safe_css(css: &str) -> anyhow::Result<Vec<SafeCssRule<'_>>> {
    if css.is_empty() || css.len() > CSS_LIMIT {
        bail!("theme.css 为空或超过 256 KiB 限制");
    }
    if css.chars().any(forbidden_css_character)
        || css.contains("/*")
        || css.contains("*/")
        || css.contains('\\')
    {
        bail!("theme.css 包含不允许的控制字符、注释或转义");
    }
    let allowed_parts = [
        "root",
        "sidebar",
        "main",
        "header",
        "home",
        "home-hero",
        "project-list",
        "thread",
        "message",
        "composer",
        "composer-toolbar",
        "dialog",
    ];
    let mut parsed = Vec::new();
    let mut declarations = 0usize;
    let mut rest = css;

View on GitHub (pinned to b1ed92e5e4)