Repository: wicket Updated Branches: refs/heads/master 673fd05dd -> b8e1d5ce8
WICKET-6290 fix CssUrlReplacer so it does not mangle data URIs Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/a8823997 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/a8823997 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/a8823997 Branch: refs/heads/master Commit: a8823997fbcd326baa8fafbccfc386ff01c14c4d Parents: ce66c24 Author: Carl-Eric Menzel <cmen...@apache.org> Authored: Mon Nov 28 14:27:40 2016 +0100 Committer: Carl-Eric Menzel <cmen...@apache.org> Committed: Mon Nov 28 14:27:40 2016 +0100 ---------------------------------------------------------------------- .../org/apache/wicket/resource/CssUrlReplacer.java | 7 +++++++ .../apache/wicket/resource/CssUrlReplacerTest.java | 14 ++++++++++++-- .../src/main/java/org/apache/wicket/request/Url.java | 11 +++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/a8823997/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 ab0f45f..a19fe2e 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/a8823997/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 5503e4c..5681eaa 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 @@ -35,8 +35,6 @@ import org.apache.wicket.util.tester.WicketTestCase; import org.junit.Before; import org.junit.Test; -import java.util.Locale; - public class CssUrlReplacerTest extends WicketTestCase { @@ -92,6 +90,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/a8823997/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 be49640..4a078df 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 @@ -493,6 +493,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.