-
-
Notifications
You must be signed in to change notification settings - Fork 192
fix: parsing of srcset URLs after the first URL #1890
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
Conversation
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
8fed2ef to
b589a56
Compare
info messages be a warning instead?
thomas-zahner
left a comment
There was a problem hiding this 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> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
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 600wreally, 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:
related to #1190