Repository: wicket Updated Branches: refs/heads/wicket-6.x b29055db8 -> 6400416cd
WICKET-6290 fix CssUrlReplacer so it does not mangle data URIs Merge branch 'wicket6/WICKET-6290-cssurlreplacer-data-urls' into wicket-6.x Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/6400416c Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/6400416c Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/6400416c Branch: refs/heads/wicket-6.x Commit: 6400416cd238052ac41a6365e70369d1b4593151 Parents: b29055d Author: Carl-Eric Menzel <cmen...@apache.org> Authored: Mon Dec 5 11:35:46 2016 +0100 Committer: Carl-Eric Menzel <cmen...@apache.org> Committed: Mon Dec 5 11:35:46 2016 +0100 ---------------------------------------------------------------------- .../java/org/apache/wicket/resource/CssUrlReplacer.java | 7 +++++++ .../org/apache/wicket/resource/CssUrlReplacerTest.java | 12 ++++++++++++ .../src/main/java/org/apache/wicket/request/Url.java | 11 +++++++++++ 3 files changed, 30 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/6400416c/wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacer.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacer.java b/wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacer.java index 0490ea6..8d55e2f 100644 --- a/wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacer.java +++ b/wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacer.java @@ -108,6 +108,11 @@ public class CssUrlReplacer implements IScopeAwareTextResourceProcessor, ICssCom { processedUrl = imageCandidateUrl.toString(); } + else if (imageCandidateUrl.isDataUrl()) + { + embedded = true; + processedUrl = imageCandidateUrl.toString(); + } else { // relativize against the url for the containing CSS file @@ -139,6 +144,8 @@ public class CssUrlReplacer implements IScopeAwareTextResourceProcessor, ICssCom } } + + // embedded data urls don't need single quotes, but regular urls do: matcher.appendReplacement(output, embedded ? "url(" + processedUrl + ")" : "url('" + processedUrl + "')"); } http://git-wip-us.apache.org/repos/asf/wicket/blob/6400416c/wicket-core/src/test/java/org/apache/wicket/resource/CssUrlReplacerTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/resource/CssUrlReplacerTest.java b/wicket-core/src/test/java/org/apache/wicket/resource/CssUrlReplacerTest.java index 85973f9..58ee5fc 100644 --- a/wicket-core/src/test/java/org/apache/wicket/resource/CssUrlReplacerTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/resource/CssUrlReplacerTest.java @@ -71,6 +71,18 @@ public class CssUrlReplacerTest extends WicketTestCase } @Test + public void doNotProcessDataUrls_WICKET_6290() + { + String input = ".class {background-image: url(data:image/gif;base64,R0lGODlhEAAQAMQAAORHH);}"; + Class<?> scope = CssUrlReplacerTest.class; + String cssRelativePath = "res/css/some.css"; + CssUrlReplacer replacer = new CssUrlReplacer(); + + String processed = replacer.process(input, scope, cssRelativePath); + assertThat(processed, is(input)); + } + + @Test public void doNotProcessContextAbsoluteUrls() { String input = ".class {background-image: url('/some.img');}"; http://git-wip-us.apache.org/repos/asf/wicket/blob/6400416c/wicket-request/src/main/java/org/apache/wicket/request/Url.java ---------------------------------------------------------------------- diff --git a/wicket-request/src/main/java/org/apache/wicket/request/Url.java b/wicket-request/src/main/java/org/apache/wicket/request/Url.java index 3a939b9..85ecf21 100755 --- a/wicket-request/src/main/java/org/apache/wicket/request/Url.java +++ b/wicket-request/src/main/java/org/apache/wicket/request/Url.java @@ -505,6 +505,17 @@ public class Url implements Serializable } /** + * Returns whether the Url is a CSS data uri. Data uris start with '{@literal data:}'. + * + * @return <code>true</code> if Url starts with 'data:', <code>false</code> otherwise. + */ + public boolean isDataUrl() + { + return (getProtocol() != null && getProtocol().equals("data")) || (!getSegments().isEmpty() && getSegments() + .get(0).startsWith("data")); + } + + /** * Returns whether the Url has a <em>host</em> attribute. * The scheme is optional because the url may be <code>//host/path</code>. * The port is also optional because there are defaults for the different protocols.