Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serialization & deserialization issue #286

Closed
charlesxsh opened this issue Jul 14, 2021 · 2 comments
Closed

serialization & deserialization issue #286

charlesxsh opened this issue Jul 14, 2021 · 2 comments

Comments

@charlesxsh
Copy link

Input

al9�999999999999999999999dkfjjal`kj]fakY{djfjfla{djflkd

Output

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `[Ident("al9"), Delim('\u{19}'), Dimension { has_sign: false, value: 1000000000000000000000.0, int_value: Some(2147483647), unit: "dkfjjal" }, Delim('`'), Ident("kj"), CloseSquareBracket, Ident("fakY"), CurlyBracketBlock]`,
 right: `[Ident("al9"), Delim('\u{19}'), Dimension { has_sign: false, value: 1000000000000000000000.0, int_value: None, unit: "dkfjjal" }, Delim('`'), Ident("kj"), CloseSquareBracket, Ident("fakY"), CurlyBracketBlock]`', css-vrf.rs:44:5

Expect

left & right should be the same?

code

use cssparser::{Parser, ParserInput, ToCss, Token};
// let data = input
// parse `data` into tokens
let str1 = match std::str::from_utf8(data) {
    Ok(d) => d,
    Err(..) => return,
};
let tokens1: Vec<Token> = {
    let mut parser_input = ParserInput::new(str1);
    let mut parser = Parser::new(&mut parser_input);
    let mut tokens = vec![];
    while let Ok(token) = parser.next_including_whitespace_and_comments() {
        tokens.push(token.clone())
    }
    tokens
};

// dump the tokens into a string and parse again into tokens
let str2 = tokens1
    .iter()
    .map(|t| t.to_css_string())
    .collect::<String>();
let tokens2: Vec<Token> = {
    let mut parser_input = ParserInput::new(&str2);
    let mut parser = Parser::new(&mut parser_input);
    let mut tokens = vec![];
    while let Ok(token) = parser.next_including_whitespace_and_comments() {
        tokens.push(token.clone())
    }
    tokens
};

assert_eq!(tokens1, tokens2);
@saona-raimundo
Copy link

Related to #165

@emilio
Copy link
Member

emilio commented Aug 2, 2023

Dupe of #165 indeed.

@emilio emilio closed this as completed Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants