fix: stop crashing on protocol-relative image source URLs - #2365
Closed
uuzzrm wants to merge 1 commit into
Closed
Conversation
new URL() without a base throws on //host/... and /path/... source URLs, and the lightbox slides are rebuilt on every render, so a single result with such a URL replaced the whole image section with the error alert. Image and video engines return these routinely (iframe_src from SearXNG video results, relative img_src values on some image engines). Use the getHostname() helper the component already uses for the aria-label and the Visit link, which falls back to the raw string when parsing fails. Regression test covers both a protocol-relative and a relative source URL.
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2363
new URL(sourceUrl).hostnamethrows on protocol-relative (//www.youtube.com/embed/...) and relative (/images/...) source URLs, and since the lightbox slides are rebuilt on every render, a single bad result swapped the whole image section for the "Error loading search results" alert.Video results come in as SearXNG
iframe_src, which engines routinely return protocol-relative (YouTube embeds especially), and some image engines return relativeimg_srcvalues too, so this isn't an exotic case.Swapped the label to the existing
getHostname()helper — it already falls back to the raw string for unparseable URLs and is what this same component uses for the aria-label and the "Visit" link.Added a regression test with a protocol-relative and a relative source URL; before the change the render threw
TypeError: Invalid URL.Verified with
vitest run,biome check, andtsc.