Skip to content

[Invalid] Tokenizer error #336

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

Closed
audioXD opened this issue Apr 30, 2023 · 0 comments
Closed

[Invalid] Tokenizer error #336

audioXD opened this issue Apr 30, 2023 · 0 comments

Comments

@audioXD
Copy link

audioXD commented Apr 30, 2023

Correction

It is the intended output as descibed in 4.3.7. Consume an escaped code point, I just read teh spec wring

EOF

This is a parse error. Return U+FFFD REPLACEMENT CHARACTER (�).

So ignore the bottom issue

Error while Tokenizing/Parsing

Input: \
Output: Ident("�")
Expected: Delim('\\')

Specification

In the CSS3 spec in 4.3. Tokenizer Algorithms it is stated :

U+005C REVERSE SOLIDUS (\)

If the input stream starts with a valid escape, reconsume the current input code point, consume an ident-like token, and return it.

Otherwise, this is a parse error. Return a <delim-token> with its value set to the current input code point.

NOTE there may be formatting errors since I copy pasted the doc.

Test

let mut input = cssparser::ParserInput::new("\\");
let mut parser = cssparser::Parser::new(&mut input);
assert_eq!(parser.next_including_whitespace_and_comments(), Ok(&cssparser::Token::Delim('\\')));

Output:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `Ok(Ident("�"))`,
 right: `Ok(Delim('\\'))`', examples/error.rs:6:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Cause

In ./src/tokenizer.rs:647 the bug is that it only checks if next is a new line.

b'\\' => {
    if !tokenizer.has_newline_at(1) { consume_ident_like(tokenizer) }
    else { tokenizer.advance(1); Delim('\\') }
},

Recommendation

Insted of tokenizer.has_newline_at(1) make and call tokenizer.has_escape()

@audioXD audioXD closed this as completed Apr 30, 2023
@audioXD audioXD changed the title Tokenizer error [Invalid] Tokenizer error Apr 30, 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

1 participant