servo / servo/rust-cssparser

Round-trip parsing and output generation causes difference in parsed result

Open
#165 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
869
Forks
152
Avg merge
15h 8m
Merged PRs (30d)
12

Description

Found this while fuzzing.

extern crate cssparser;

use cssparser::ToCss;

fn main() {
    let input = "\\\n3:\'\\\x0c";
    println!("input:\n\t{:?}", input);

    let mut parser_input = cssparser::ParserInput::new(input);
    let mut parser = cssparser::Parser::new(&mut parser_input);
    let tokens = parser
        .next_including_whitespace_and_comments()
        .into_iter()
        .collect::<Vec<_>>();
    println!("tokens:\n\t{:?}", tokens);

    let str2 = tokens.iter().map(|t| t.to_css_string()).collect::<String>();
    println!("tokens to string:\n\t{:?}", str2);

    let mut parser_input = cssparser::ParserInput::new(&str2);
    let mut parser = cssparser::Parser::new(&mut parser_input);
    let tokens2 = parser
        .next_including_whitespace_and_comments()
        .into_iter()
        .collect::<Vec<_>>();
    println!("tokens to string to tokens:\n\t{:?}", tokens2);
}
input:
	"\\\n3:\'\\\u{c}"
tokens:
	[Delim('\\')]
tokens to string:
	"\\"
tokens to string to tokens:
	[Ident("�")]

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the Rust reproducer from the issue and compare the two token lists for the shown input. Trace the token parsing and ToCss serialization paths involved; the fix is complete when parsing the generated string preserves the original parsed result and the regression is covered by a test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.