Skip to content

Rewrite relative URLs in srcset attributes (#1952) - #1977

Open
aryankalantri wants to merge 5 commits into
apache:masterfrom
aryankalantri:fix/srcset-relative-path-1952
Open

aryankalantri wants to merge 5 commits into
apache:masterfrom
aryankalantri:fix/srcset-relative-path-1952

Conversation

@aryankalantri

Copy link
Copy Markdown

Fixes #1952.

Inside <wicket:link> (and for relative paths in general), Wicket rewrites the URLs in href, src and background attributes so they resolve relative to the page's package. The srcset attribute of <img> and <source> was not rewritten, so responsive images in static markup broke.

What changed

RelativePathPrefixHandler now rewrites srcset the same way it rewrites src:

  • Each comma-separated url descriptor candidate is rewritten on its own with UrlUtils.rewriteToContextRelative, keeping its descriptor (480w, 2x, ...).
  • Absolute URLs, absolute paths and fragments are left alone, using the same guards as the single-URL attributes. A srcset holding only absolute URLs does not get the behavior attached.
  • The shared isRelativeUrl check is now used for the existing attributes too (no behavior change there).

Scope notes (decisions from the issue):

  • srcset is only handled in RelativePathPrefixHandler (plain markup). Inside <wicket:link>, AutoLinkResolver resolves one attribute to one package resource, so a multi-URL srcset cannot be auto-linked the same way; that stays unhandled and is out of scope here.
  • A data: URI in srcset is out of scope: it contains a comma by construction, so the comma-split parsing cannot tell its payload apart from a second candidate.

How tested

New srcset() test in RelativePathPrefixHandlerTest with Page_4 fixtures: two relative candidates on <img>, a mixed relative/absolute-path/absolute-URL srcset, a <source srcset> inside <picture> plus an <img src> fallback, and a 2x descriptor.

  • RelativePathPrefixHandlerTest: 4/4 pass with the fix. The new test fails on unmodified master (expected output not produced), so it detects the bug.
  • Full org.apache.wicket.markup.parser package: 51/51 pass.

Tests were run locally with a manual javac build (JDK 21) because Maven cannot download dependencies in this environment: Java TLS through the egress proxy is reset, while curl works. The full mvn verify run is left to CI as arbiter.

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.

Rewrite srcset attributes inside wicket:link

1 participant