Skip to content

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

@frewsxcv

Description

@frewsxcv

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("�")]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions