Skip to content

Commit 07d1046

Browse files
committed
ignore not parsable URls in css function url() on "rewrite-urls". see
#54
1 parent d9aa204 commit 07d1046

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

src/com/inet/lib/less/FunctionExpression.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import static com.inet.lib.less.ColorUtils.toHSL;
5353
import static com.inet.lib.less.ColorUtils.toHSV;
5454

55+
import java.net.MalformedURLException;
5556
import java.net.URI;
5657
import java.net.URISyntaxException;
5758
import java.net.URL;
@@ -242,12 +243,16 @@ public void appendTo( CssFormatter formatter ) {
242243
String url = get( 1 ).stringValue( formatter );
243244
String urlStr = UrlUtils.removeQuote( url );
244245
if( formatter.isRewriteUrl( urlStr ) ) {
245-
String relativeUrlStr = get( 0 ).stringValue( formatter );
246-
URL relativeUrl = new URL( "file", null, relativeUrlStr );
247-
relativeUrl = new URL( relativeUrl, urlStr );
248-
boolean quote = url != urlStr;
249-
urlStr = relativeUrl.getPath();
250-
url = quote ? url.charAt( 0 ) + urlStr + url.charAt( 0 ) : urlStr;
246+
try {
247+
String relativeUrlStr = get( 0 ).stringValue( formatter );
248+
URL relativeUrl = new URL( "file", null, relativeUrlStr );
249+
relativeUrl = new URL( relativeUrl, urlStr );
250+
boolean quote = url != urlStr;
251+
urlStr = relativeUrl.getPath();
252+
url = quote ? url.charAt( 0 ) + urlStr + url.charAt( 0 ) : urlStr;
253+
} catch ( MalformedURLException ex ) {
254+
// ignore, occur with data: protocol
255+
}
251256
}
252257
formatter.append( "url(" );
253258
formatter.append( url );

test/com/inet/lib/less/RewriteUrls/all.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
url4: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
1414
url5: url('subfolder1/DoesNotExists.jpg');
1515
url4: url('subfolder1/subfolder1/DoesNotExists.jpg');
16+
url5: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
1617
}

test/com/inet/lib/less/RewriteUrls/local.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
url4: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
1414
url5: url('DoesNotExists.jpg');
1515
url4: url('subfolder1/DoesNotExists.jpg');
16+
url5: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
1617
}

test/com/inet/lib/less/RewriteUrls/off.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
url4: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
1414
url5: url('DoesNotExists.jpg');
1515
url4: url('subfolder1/DoesNotExists.jpg');
16+
url5: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
1617
}

test/com/inet/lib/less/RewriteUrls/subfolder1/sub1.less

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
url3: url('subfolder1/image.jpg');
77
url4: data-uri('subfolder1/image.jpg');
88
url5: data-uri('DoesNotExists.jpg');
9-
url4: data-uri('subfolder1/DoesNotExists.jpg');
9+
url4: data-uri('subfolder1/DoesNotExists.jpg');
10+
url5: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
1011
}

0 commit comments

Comments
 (0)