Repository: tapestry-5
Updated Branches:
  refs/heads/master 2c9ea8a93 -> 097d0fe36


TAP5-2129: expand asset: URLs in CSS


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

Branch: refs/heads/master
Commit: 097d0fe36a5d7b7f31cf5e20d784f4d56f63653d
Parents: 2c9ea8a
Author: Jochen Kemnade <[email protected]>
Authored: Thu Feb 12 19:20:27 2015 +0100
Committer: Jochen Kemnade <[email protected]>
Committed: Thu Feb 12 19:20:27 2015 +0100

----------------------------------------------------------------------
 .../services/assets/CSSURLRewriter.java         |  8 +++--
 .../services/assets/CSSURLRewriterTests.groovy  | 35 ++++++++++++++++++++
 2 files changed, 40 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/097d0fe3/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 1a60a10..9d9ccb3 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
@@ -147,9 +147,11 @@ public class CSSURLRewriter extends DelegatingSRS
         {
             String url = matcher.group(2); // the string inside the quotes
 
-            // When the URL starts with a slash, there's no need to rewrite it 
(this is actually rare in Tapestry
-            // as you want to use relative URLs to leverage the asset pipeline.
-            if (completeURLPattern.matcher(url).find())
+            // When the URL starts with a slash or a scheme (e.g. http: or 
data:) , there's no need
+            // to rewrite it (this is actually rare in Tapestry as you want to 
use relative URLs to
+            // leverage the asset pipeline.
+            Matcher completeURLMatcher = completeURLPattern.matcher(url);
+            if (completeURLMatcher.find() && 
!("asset:".equals(completeURLMatcher.group(1))))
             {
                 String queryParameters = matcher.group(3);
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/097d0fe3/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 4b8752c..e6e6646 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
@@ -127,6 +127,41 @@ body {
     }
 
     @Test
+    void asset_urls_are_expanded() {
+        def input = '''
+body {
+  background: white url("asset:context:images/back.png") attach-x;
+}
+'''
+
+        def assetSource = newMock AssetSource
+        def resource = newMock Resource
+        def asset = newMock Asset
+
+        expect(
+            assetSource.getAsset(resource, "asset:context:images/back.png", 
null)
+        ).andReturn asset
+
+        expect(asset.toClientURL()).andReturn "/ctx/images/back.png"
+
+        replay()
+
+
+        def rewriter = new CSSURLRewriter(null, null, assetSource, null, false)
+
+        def output = rewriter.replaceURLs input, resource
+
+        assertEquals output, '''
+body {
+  background: white url("/ctx/images/back.png") attach-x;
+}
+'''
+
+        verify()
+
+    }
+
+    @Test
     void absolute_urls_not_replaced() {
         def input = '''
 body {

Reply via email to