You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2015/02/06 08:18:38 UTC
wicket git commit: WICKET-5827 Allow to apply multiple Javascript /
CSS compressors
Repository: wicket
Updated Branches:
refs/heads/pr-87-css_js_compression 08f8a5567 -> ab7426158
WICKET-5827 Allow to apply multiple Javascript / CSS compressors
Do not manipulate full and absolute image urls
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/ab742615
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/ab742615
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/ab742615
Branch: refs/heads/pr-87-css_js_compression
Commit: ab742615819af1738ba4612fc4aa81331dbebeb3
Parents: 08f8a55
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Fri Feb 6 09:18:11 2015 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Fri Feb 6 09:18:11 2015 +0200
----------------------------------------------------------------------
.../apache/wicket/resource/CssUrlReplacer.java | 22 +++++++++--
.../wicket/resource/CssUrlReplacerTest.java | 40 ++++++++++++++++++++
2 files changed, 58 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/ab742615/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 985c275..47a0d47 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
@@ -56,10 +56,24 @@ public class CssUrlReplacer implements IScopeAwareTextResourceProcessor
while (matcher.find())
{
- Url imageRelativeUrl = Url.parse(matcher.group(1));
- Url cssUrlCopy = new Url(cssUrl);
- cssUrlCopy.resolveRelative(imageRelativeUrl);
- matcher.appendReplacement(output, "url('" + cssUrlCopy.toString() + "')");
+ Url imageCandidateUrl = Url.parse(matcher.group(1));
+ String processedUrl;
+ if (imageCandidateUrl.isFull())
+ {
+ processedUrl = imageCandidateUrl.toString(Url.StringMode.FULL);
+ }
+ else if (imageCandidateUrl.isContextAbsolute())
+ {
+ processedUrl = imageCandidateUrl.toString();
+ }
+ else
+ {
+ // relativize against the url for the containing CSS file
+ Url cssUrlCopy = new Url(cssUrl);
+ cssUrlCopy.resolveRelative(imageCandidateUrl);
+ processedUrl = cssUrlCopy.toString();
+ }
+ matcher.appendReplacement(output, "url('" + processedUrl + "')");
}
matcher.appendTail(output);
return output.toString();
http://git-wip-us.apache.org/repos/asf/wicket/blob/ab742615/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 157bd60..d8f013c 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
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.wicket.resource;
import static org.hamcrest.Matchers.containsString;
@@ -9,6 +25,30 @@ import org.junit.Test;
public class CssUrlReplacerTest extends WicketTestCase
{
@Test
+ public void doNotProcessFullUrls()
+ {
+ String input = ".class {background-image: url('http://example.com/some.img');}";
+ 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('http://example.com/some.img');}"));
+ }
+
+ @Test
+ public void doNotProcessContextAbsoluteUrls()
+ {
+ String input = ".class {background-image: url('/some.img');}";
+ 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('/some.img');}"));
+ }
+
+ @Test
public void sameFolderSingleQuotes()
{
String input = ".class {background-image: url('some.img');}";