Skip to content

xml5ever: Keep a carriage return that follows a named character reference - #817

Closed
joszamama wants to merge 1 commit into
servo:mainfrom
joszamama:fix/xml5ever-cr-after-char-ref
Closed

joszamama wants to merge 1 commit into
servo:mainfrom
joszamama:fix/xml5ever-cr-after-char-ref

Conversation

@joszamama

Copy link
Copy Markdown

In xml5ever, a CR right after a named character reference was dropped: <a>&lt; CR y</a> gave "<y" instead of "<\ny". do_named read the next character with get_char, which turns CR into LF and sets ignore_lf, so the LF that was pushed back got skipped on the next read.

This ports the html5ever fix from #460: do_named uses peek and discard_char, and discard_char drops one raw input character. The other callers of discard_char already pair it with peek.

Fixes #816

Testing: the new unit test carriage_return_after_char_ref fails without the change and passes with it. cargo test --all (with both test submodules) passes on main with 29529 tests and on this branch with 29530, and cargo fmt --all -- --check is clean.

As said in the issue, I used AI to help draft this patch and text, and I checked that I understand the change. Feel free to use it or close it.

…ence

The named character reference state read each character with get_char(),
which turns CR into LF and sets the flag that skips the LF of a CR LF
pair. A CR right after the reference was read this way and given back to
the input as LF, so the next read skipped it and "&lt;\ry" became "<y".

Read the name with peek() and discard_char() instead, and make
discard_char() drop one raw input character, as html5ever's tokenizer
already does.

Signed-off-by: joszamama <joszamama@gmail.com>
@mrobinson

Copy link
Copy Markdown
Member

@joszamama When you say that you used AI to help do you mean that it generated the code?

@mrobinson mrobinson closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

V-non-breaking A non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xml5ever: a carriage return right after a named character reference is lost

2 participants