Skip to content

Fix URI parsing inside verbatim content - #2335

Open
k0tran wants to merge 2 commits into
lycheeverse:masterfrom
k0tran:fix-html5ever-verbatim
Open

k0tran wants to merge 2 commits into
lycheeverse:masterfrom
k0tran:fix-html5ever-verbatim

Conversation

@k0tran

@k0tran k0tran commented Nov 6, 2026

Copy link
Copy Markdown

PR as per requested in #2263 (comment)

Note that it is not covered by tests unless SIMD is disabled inside html5ever or built on a target that html5ever does not have support SIMD for. When developing the primary goal was set of minimal changes to build lychee on riscv64 and loongarch64.

Also, this patch is LLM-assisted. I tried my best to review as thorough as possible and ran another context-less instance for code review.

@mre mre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with my review. Added a few comments.
Thanks for pointing out LLM usage.

Can we add a test for that new behavior somehow?

Comment on lines +28 to +30
// The column on the first line of the input is only meaningful if the input started at
// the beginning of a line.
if span.line.get() == 1 && !self.at_line_start {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems clearer, thanks.

Comment on lines +65 to +68
let at_line_start = self.at_line_start.replace(match &token {
Token::CharacterTokens(raw) => raw.ends_with('\n'),
_ => false,
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this easier to read if the bool is defined in its own line:

// A token starts at the beginning of a line only if the preceding token
// was character data ending in a newline. For all other token types,
// the starting column of the next token is unknown.
let next_at_line_start = matches!(
    &token,
    Token::CharacterTokens(raw) if raw.ends_with('\n')
);

let at_line_start = self.at_line_start.replace(next_at_line_start);

Current URI parsing does not process correcty cases when
Token::CharacterTokens contains several URI's separated by \n which is
tested by `test_include_verbatim`. Those cases can be encountered on
non-SIMD path of html5ever.
@k0tran
k0tran force-pushed the fix-html5ever-verbatim branch from 4ccb98e to 098c375 Compare November 13, 2026 14:51
@k0tran

k0tran commented Nov 13, 2026

Copy link
Copy Markdown
Author

The requested change implemented. Test added.

Verified that regardless of SIMD before the fixing commit it breaks and after that commit passes.

@k0tran

k0tran commented Nov 13, 2026

Copy link
Copy Markdown
Author

Hmm forgot to run clippy, one sec

@k0tran
k0tran force-pushed the fix-html5ever-verbatim branch from 5f4f6fe to 2dab8ad Compare November 13, 2026 15:19
@k0tran

k0tran commented Nov 13, 2026

Copy link
Copy Markdown
Author

Oh, I get it, I changed the formatting inside HTML_INPUT and it broke the test.

html5ever character tokens can span multiple lines. Verify that a URI
on the first line of a token starting at the beginning of a line keeps
its column.
@k0tran
k0tran force-pushed the fix-html5ever-verbatim branch from 2dab8ad to 5f69a31 Compare November 13, 2026 15:57
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

Successfully merging this pull request may close these issues.

2 participants