dashorst opened a new issue, #2018: URL: https://github.com/apache/wicket/issues/2018
`Url#resolveRelative` keeps the fragment of the base url and ignores the fragment of the relative url. Resolving a relative reference should give the result the reference's fragment ([RFC 3986, section 5.2.2](https://www.rfc-editor.org/rfc/rfc3986#section-5.2.2): `T.fragment = R.fragment`), the same way `resolveRelative` already takes the reference's query parameters. ```java Url url = Url.parse("c/d#top"); url.resolveRelative(Url.parse("a#section")); url.toString(); // "c/a#top", expected "c/a#section" ``` `resolveRelative` has two callers: - `UrlRenderer#renderFullUrl` — this is #1950. PR #1967 works around it there by setting the fragment after `resolveRelative`. - `CssUrlReplacer` — a relative url with a fragment in a stylesheet loses it, so `background: url('icons.svg#arrow')` is rewritten to the url of `icons.svg`, and the browser shows the whole sprite instead of the one icon. Fixing `resolveRelative` alone is not enough for `CssUrlReplacer`: it uses the resolved url as the name of a `PackageResourceReference`. With the fragment kept, the stylesheet gets `.../icons.svg%23arrow`, and requesting it fails with `PackageResourceBlockedException` for a resource named `icons.svg#arrow`. `CssUrlReplacer` has to leave the fragment out of the resource name and append it to the url it renders. Once `resolveRelative` is fixed, the workaround in `UrlRenderer#renderFullUrl` can go. ## Test cases Both fail on current master. In `wicket-request/src/test/java/org/apache/wicket/request/UrlTest.java`: ```java @Test void resolveRelativeTakesFragmentOfRelative() { Url baseUrl = Url.parse("c/d#top"); baseUrl.resolveRelative(Url.parse("a#section")); assertEquals("c/a#section", baseUrl.toString()); baseUrl = Url.parse("c/d#top"); baseUrl.resolveRelative(Url.parse("a")); assertEquals("c/a", baseUrl.toString()); } ``` ``` expected: <c/a#section> but was: <c/a#top> ``` In `wicket-core-tests/src/test/java/org/apache/wicket/resource/CssUrlReplacerTest.java`: ```java @Test void keepFragment() { String input = ".class {background-image: url('some.svg#arrow');}"; Class<?> scope = CssUrlReplacerTest.class; String cssRelativePath = "res/css/some.css"; CssUrlReplacer replacer = new CssUrlReplacer(); String processed = replacer.process(input, scope, cssRelativePath); assertThat( processed, is(".class {background-image: url('./wicket/resource/org.apache.wicket.resource.CssUrlReplacerTest/res/css/some.svg" + DECORATION_SUFFIX + "#arrow');}")); } ``` ``` Expected: is ".class {background-image: url('./wicket/resource/org.apache.wicket.resource.CssUrlReplacerTest/res/css/some.svg--decorated#arrow');}" but: was ".class {background-image: url('./wicket/resource/org.apache.wicket.resource.CssUrlReplacerTest/res/css/some.svg--decorated');}" ``` `resolveRelative` is public API, so the change in behaviour needs a mention in the commit message. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
