needs_separator_when_before omits CDC, so serialized tokens re-parse wrong
还没有人认领这个 Issue。
评估
调研方向
从 src/serializer.rs 第 519 行附近开始阅读 needs_separator_when_before,尤其关注 Number、DelimHash、DelimAt 和 DelimMinus 对应的行。根据 issue 的复现用例和现有的 serializer 覆盖情况,验证四种 CDC 组合。完成标准是每种组合都会请求一个分隔符,并且序列化后的 token 重新解析后得到原始 token 序列。
由索引模型根据 Issue 内容生成。
描述
TokenSerializationType::needs_separator_when_before returns false when a Number, DelimHash, DelimAt, or DelimMinus is followed by CDC. Concatenating the two serializations produces text that tokenizes into different tokens than the input.
Reproducer
cssparser 0.37.0, default features.
use cssparser::{Parser, ParserInput, ToCss};
fn main() {
let mut pi = ParserInput::new("5 -->");
let mut p = Parser::new(&mut pi);
let a = p.next().unwrap().clone(); // Number { value: 5.0, int_value: Some(5) }
let b = p.next().unwrap().clone(); // CDC
// no separator requested
assert!(!a
.serialization_type()
.needs_separator_when_before(b.serialization_type()));
let mut s = String::new();
a.to_css(&mut s).unwrap();
b.to_css(&mut s).unwrap();
assert_eq!(s, "5-->");
}
Observed vs expected
Observed: the call returns false and serialization yields 5-->. Re-parsing 5--> gives Dimension { value: 5.0, unit: "--" } followed by Delim('>').
Expected: true, which signals that an empty comment is needed so the output round-trips. The doc comment on needs_separator_when_before says it returns true if "an empty comment /**/ needs to be inserted between them so that they are not re-parsed as a single token". CSS Syntax Level 3 §Serialization requires the serialized form to round-trip.
Root cause
src/serializer.rs:519. The Ident and AtKeywordOrHash | Dimension rows list CDC. The rows covering Number, DelimHash, DelimAt, and DelimMinus do not.
Scope
Four pairs return false: Number then CDC gives 5-->, re-parsing as Dimension{5,"--"} + Delim('>'). DelimHash then CDC gives #-->, re-parsing as IDHash("--") + Delim('>'). DelimAt then CDC gives @-->, re-parsing as AtKeyword("--") + Delim('>'). DelimMinus then CDC gives --->, re-parsing as Ident("---") + Delim('>').
Any consumer using this API to re-emit CSS is affected. Stylo calls it for custom-property and var() substitution serialization. Present on main as of the 2026-07-21 commit.
- 主要语言
- Rust
- 星标
- 869
- 派生
- 152
- 平均合并
- 15 小时 8 分钟
- 30 天内合并 PR
- 12
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
servo/rust-cssparser 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
servo/rust-cssparser#440 ·
-
难度 2/5 1-3 小时 新手友好度 85/100
servo/rust-cssparser#439 ·
-
难度 4/5 3-5 天 新手友好度 45/100
servo/rust-cssparser#438 · 3 条评论 · 1 个 reaction ·
-
难度 5/5 一周以上 新手友好度 28/100
servo/rust-cssparser#436 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 45/100
servo/rust-cssparser#423 · 5 条评论 ·
查看 servo/rust-cssparser 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
gitbutlerapp/gitbutler#15998 · 1 条评论 ·
-
bug triage:deciding
难度 1/5 1 小时以内 新手友好度 88/100
open-telemetry/otel-arrow#4132 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
-
难度 2/5 1-3 小时 新手友好度 84/100