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/07/25 00:06:13 UTC
git commit: Handle multiple url()s on a single line
Updated Branches:
refs/heads/master 0dd2d2ae7 -> a32faa924
Handle multiple url()s on a single line
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/a32faa92
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/a32faa92
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/a32faa92
Branch: refs/heads/master
Commit: a32faa924eb8b6f9a5fb7c43d7bf659e56743e26
Parents: 0dd2d2a
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Wed Jul 24 15:06:07 2013 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed Jul 24 15:06:07 2013 -0700
----------------------------------------------------------------------
.../services/assets/CSSURLRewriter.java | 21 ++++++++---
.../services/assets/CSSURLRewriterTests.groovy | 39 +++++++++++++++++++-
2 files changed, 54 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a32faa92/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 3577dad..95ba2ba 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
@@ -33,8 +33,8 @@ import java.util.regex.Pattern;
* CSS file will change (which would ordinarily break relative URLs), and for changing the relative directories of
* the CSS file and the image assets it may refer to (useful for incorporating a hash of the resource's content into
* the exposed URL).
- *
- * <p>
+ * <p/>
+ * <p/>
* One potential problem with URL rewriting is the way that URLs for referenced resources are generated; we are
* somewhat banking on the fact that referenced resources are non-compressable images.
*
@@ -45,7 +45,16 @@ 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
// Group 3 is any query parmameters (see issue TAP5-2106)
- private final Pattern urlPattern = Pattern.compile("url\\(\\s*(['\"]?)(.+?)(\\?.*)?\\1\\s*\\)", Pattern.MULTILINE);
+ private final Pattern urlPattern = Pattern.compile(
+ "url" +
+ "\\(" + // opening paren
+ "\\s*" +
+ "(['\"]?)" + // group 1: optional single or double quote
+ "(.+?)" + // group 2: the main part of the URL, up to the first '#' or '?'
+ "([\\#\\?].*?)?" + // group 3: Optional '#' or '?' to end of string
+ "\\1" + // optional closing single/double quote
+ "\\s*" +
+ "\\)"); // matching close paren
// Does it start with a '/' or what looks like a scheme ("http:")?
private final Pattern completeURLPattern = Pattern.compile("^[#/]|(\\p{Alpha}\\w*:)");
@@ -132,7 +141,8 @@ public class CSSURLRewriter extends DelegatingSRS
{
String queryParameters = matcher.group(3);
- if (queryParameters != null) {
+ if (queryParameters != null)
+ {
url = url + queryParameters;
}
@@ -147,7 +157,8 @@ public class CSSURLRewriter extends DelegatingSRS
String assetURL = asset.toClientURL();
String queryParameters = matcher.group(3);
- if (queryParameters != null) {
+ if (queryParameters != null)
+ {
assetURL += queryParameters;
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a32faa92/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 31a58db..6286a83 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,7 +57,6 @@ body {
}
-
// See TAP5-2106
@Test
void query_parameters_in_relative_url_are_maintained() {
@@ -153,6 +152,44 @@ body {
assertNull rewriter.replaceURLs(input, null)
}
+ @Test
+ void multiple_urls_per_line() {
+
+ def input = '''
+body {
+ src: url('font/fontawesome-webfont.eot?#iefix&v=3.1.0') format('embedded-opentype'), url('font/fontawesome-webfont.woff?v=3.1.0') format('woff'), url('font/fontawesome-webfont.ttf?v=3.1.0') format('truetype'), url('font/fontawesome-webfont.svg#fontawesomeregular?v=3.1.0') format('svg');
+}
+'''
+
+ def assetSource = newMock AssetSource
+ def resource = newMock Resource
+
+ ["fontawesome-webfont.eot", "fontawesome-webfont.woff", "fontawesome-webfont.ttf", "fontawesome-webfont.svg"].each { name ->
+
+ def asset = newMock Asset
+
+ expect(
+ assetSource.getAsset(resource, "font/$name", null)
+ ).andReturn asset
+
+ expect(asset.toClientURL()).andReturn "/ctx/font/$name".toString()
+ }
+
+ replay()
+
+
+ def rewriter = new CSSURLRewriter(null, null, assetSource, null)
+
+ def output = rewriter.replaceURLs input, resource
+
+ assertEquals output, '''
+body {
+ src: url("/ctx/font/fontawesome-webfont.eot?#iefix&v=3.1.0") format('embedded-opentype'), url("/ctx/font/fontawesome-webfont.woff?v=3.1.0") format('woff'), url("/ctx/font/fontawesome-webfont.ttf?v=3.1.0") format('truetype'), url("/ctx/font/fontawesome-webfont.svg#fontawesomeregular?v=3.1.0") format('svg');
+}
+'''
+ verify()
+ }
+
@Test
void vml_urls_are_not_replaced() {