You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2013/05/28 18:29:13 UTC

git commit: Handle yet another special case involving CSS urls

Updated Branches:
  refs/heads/master 22e8d1899 -> 2efe55866


Handle yet another special case involving CSS urls


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

Branch: refs/heads/master
Commit: 2efe558667201a74e2b7ed4fffc27b07ea1f89ce
Parents: 22e8d18
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Tue May 28 09:29:07 2013 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Tue May 28 09:29:07 2013 -0700

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


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/2efe5586/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 d3d76d6..3577dad 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
@@ -130,6 +130,12 @@ public class CSSURLRewriter extends DelegatingSRS
             // as you want to use relative URLs to leverage the asset pipeline.
             if (completeURLPattern.matcher(url).find())
             {
+                String queryParameters = matcher.group(3);
+
+                if (queryParameters != null) {
+                    url = url + queryParameters;
+                }
+
                 // This may normalize single quotes, or missing quotes, to double quotes, but is not
                 // considered a real change, since all such variations are valid.
                 appendReplacement(matcher, output, url);
@@ -174,7 +180,7 @@ public class CSSURLRewriter extends DelegatingSRS
 
         InputStream is = resource.openStream();
 
-        InputStreamReader reader = new InputStreamReader(resource.openStream(), "UTF-8");
+        InputStreamReader reader = new InputStreamReader(is, "UTF-8");
 
         try
         {
@@ -193,6 +199,7 @@ public class CSSURLRewriter extends DelegatingSRS
         } finally
         {
             reader.close();
+            is.close();
         }
 
         return result.toString();

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/2efe5586/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 d62ff4d..31a58db 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
@@ -208,4 +208,43 @@ div.busy {
 
     }
 
+
+    @Test
+    void query_parameters_in_absolute_url_are_maintained() {
+
+        def input = '''
+@import url(https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic);
+
+div.busy {
+  background-image: url( "images/ajax.gif" );
+}
+'''
+
+        def assetSource = newMock AssetSource
+        def resource = newMock Resource
+        def asset = newMock Asset
+
+        expect(
+            assetSource.getAsset(resource, "images/ajax.gif", null)
+        ).andReturn asset
+
+        expect(asset.toClientURL()).andReturn "/ctx/images/ajax.gif"
+
+        replay()
+
+        def rewriter = new CSSURLRewriter(null, null, assetSource, null)
+
+        def output = rewriter.replaceURLs input, resource
+
+        assertEquals output, '''
+@import url("https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic");
+
+div.busy {
+  background-image: url("/ctx/images/ajax.gif");
+}
+'''
+
+
+    }
+
 }