Skip to content

Conversation

@katrinafyi
Copy link
Member

@katrinafyi katrinafyi commented Oct 28, 2025

previously, the first character of srcset URLs past the first URL had their first character dropped. this led to absolute URLs becoming relative and other problems. this happened when the srcset did not have spaces after its commas: /300.png 300w,/600.png 600w

really, this could be fixed by simply deleting the index += 1; line. this increment causes a mismatch between the index and the remaining string which causes the off-by-one error.

this pr makes some extra changes to avoid this duplicated logic by removing the index variable entirely, since the remaining string is all you need. this avoids needing to think about indices and should avoid similar bugs in future.

this pr also changes some pattern match of space to accept other ASCII whitespace, following the spec.

for those curious, the new test case previously failed with this error:

      left: ["/300.png", "600.png", "900.png", "ttps://x.invalid/a.png", "elative.png"]
     right: ["/300.png", "/600.png", "/900.png", "https://x.invalid/a.png", "relative.png"]

related to #1190

previously, the first character of srcset URLs past the first one
had their first character dropped. this led to absolute URLs becoming
relative and other big problems. this happened when the srcset did not
have spaces after its commas: `/300.png 300w,/600.png 600w`

really, this could be fixed by simply deleting the `index += 1;` line.
this increment causes a mismatch between the index and the remaining
string which causes the off-by-one error.

this pr makes some extra changes to avoid this duplicated logic by
removing the index variable entirely, since the remaining string is all
you need. this avoids needing to think about indices and should avoid
similar bugs in future.

this pr also changes some pattern match of space to accept other ASCII
whitespace, following the spec.

for those curious, the new test case previously failed with this error:
```
      left: ["/300.png", "600.png", "900.png", "ttps://x.invalid/a.png", "elative.png"]
     right: ["/300.png", "/600.png", "/900.png", "https://x.invalid/a.png", "relative.png"]
```

related to https://www.github.com/lycheeverse/lychee/issues/1190
@katrinafyi katrinafyi force-pushed the srcset branch 2 times, most recently from 8fed2ef to b589a56 Compare October 28, 2025 01:56
info messages be a warning instead?
Copy link
Member

@thomas-zahner thomas-zahner left a comment

Choose a reason for hiding this comment

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

Ah thank you very much for this bugfix 🚀

/// Otherwise, in case of srcset syntax errors, returns Err.
///
/// <https://html.spec.whatwg.org/multipage/images.html#parsing-a-srcset-attribute>
fn parse_one_url(remaining: &str) -> Result<(&str, Option<&str>), String> {
Copy link
Member

Choose a reason for hiding this comment

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

Could you extract this function, just above skip_descriptor. Less nesting makes it more readable IMO.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! I like less indentation too

Copy link
Member

Choose a reason for hiding this comment

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

Thanks 👍

@thomas-zahner thomas-zahner merged commit fa82fc4 into lycheeverse:master Oct 30, 2025
6 checks passed
@mre mre mentioned this pull request Oct 30, 2025
@mre mre mentioned this pull request Dec 5, 2025
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