tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject [1/6] git commit: TAP5-2106: Maintain query parameters in URL
Date Fri, 17 May 2013 00:37:23 GMT
Updated Branches:
  refs/heads/master ead83fb15 -> 56a114812


TAP5-2106: Maintain query parameters in URL

In some cases, client-side code expects to see a query parameter in the URL for a CSS asset,
so it should be maintained


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/31e34098
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/31e34098
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/31e34098

Branch: refs/heads/master
Commit: 31e34098e9511fb22e06a384a1fed679706ff7d0
Parents: ead83fb
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Thu May 16 15:25:43 2013 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Thu May 16 15:25:43 2013 -0700

----------------------------------------------------------------------
 .../internal/services/assets/CSSURLRewriter.java   |    9 +++-
 .../services/assets/CSSURLRewriterTests.groovy     |   36 +++++++++++++++
 2 files changed, 44 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/31e34098/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/CSSURLRewriter.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/CSSURLRewriter.java
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/CSSURLRewriter.java
index fc673fa..cdcd847 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/CSSURLRewriter.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/CSSURLRewriter.java
@@ -44,7 +44,8 @@ public class CSSURLRewriter extends DelegatingSRS
 {
     // Group 1 is the optional single or double quote (note the use of backtracking to match
it)
     // Group 2 is the text inside the quotes, or inside the parens if no quotes
-    private final Pattern urlPattern = Pattern.compile("url\\(\\s*(['\"]?)(.+?)\\1\\s*\\)",
Pattern.MULTILINE);
+    // Group 3 is any query parmameters (see issue TAP5-2106)
+    private final Pattern urlPattern = Pattern.compile("url\\(\\s*(['\"]?)(.+?)(\\?.*)?\\1\\s*\\)",
Pattern.MULTILINE);
 
     private final OperationTracker tracker;
 
@@ -135,6 +136,12 @@ public class CSSURLRewriter extends DelegatingSRS
             Asset asset = assetSource.getAsset(baseResource, url, null);
 
             String assetURL = asset.toClientURL();
+
+            String queryParameters = matcher.group(3);
+            if (queryParameters != null) {
+                assetURL += queryParameters;
+            }
+
             appendReplacement(matcher, output, assetURL);
 
             didReplace = true;

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/31e34098/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/assets/CSSURLRewriterTests.groovy
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/assets/CSSURLRewriterTests.groovy
b/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/assets/CSSURLRewriterTests.groovy
index 5a1e6a8..4de7e04 100644
--- a/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/assets/CSSURLRewriterTests.groovy
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/assets/CSSURLRewriterTests.groovy
@@ -57,6 +57,42 @@ body {
 
     }
 
+
+    // See TAP5-2106
+    @Test
+    void query_parameters_in_relative_url_are_maintained() {
+        def input = '''
+body {
+  background: white url("images/back.png?v=1.0.0") attach-x;
+}
+'''
+
+        def assetSource = newMock AssetSource
+        def resource = newMock Resource
+        def asset = newMock Asset
+
+        expect(
+            assetSource.getAsset(resource, "images/back.png", null)
+        ).andReturn asset
+
+        expect(asset.toClientURL()).andReturn "/ctx/images/back.png"
+
+        replay()
+
+
+        def rewriter = new CSSURLRewriter(null, null, assetSource, null)
+
+        def output = rewriter.replaceURLs input, resource
+
+        assertEquals output, '''
+body {
+  background: white url("/ctx/images/back.png?v=1.0.0") attach-x;
+}
+'''
+
+
+    }
+
     @Test
     void unquoted_urls_are_matched() {
         def input = '''


Mime
View raw message