Skip to content

Commit

Permalink
Use again ReaderFactory.openStream(URL,String,String) for data-uri.
Browse files Browse the repository at this point in the history
  • Loading branch information
Horcrux7 committed Dec 7, 2020
1 parent 88d5e0a commit 2752b71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
14 changes: 6 additions & 8 deletions src/com/inet/lib/less/UrlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,18 @@ static void svgGradient( CssFormatter formatter, List<Expression> parameters ) {
* @throws IOException If any I/O errors occur on reading the content
*/
static void dataUri( CssFormatter formatter, String relativeUrlStr, final String urlString, String type ) throws IOException {
URL url = formatter.getBaseURL();
String urlStr = removeQuote( urlString );
url = new URL( url, urlStr );
if( !formatter.isRewriteUrlOff() ) {
url = new URL( new URL( formatter.getBaseURL(), relativeUrlStr ), urlStr );
}
InputStream input = null;
try {
try {
input = formatter.getReaderFactory().openStream( url );
input = formatter.getReaderFactory().openStream( formatter.getBaseURL(), urlStr, relativeUrlStr );
} catch( Exception e ) {
// try rewrite location independent of option "rewrite-urls" for backward
// compatibility, this is not 100% compatible with Less CSS
// also if is a root url, remove that to see if the file can be found right besides the base less file.
URL url = formatter.getBaseURL();
url = new URL( url, urlStr );
if( !formatter.isRewriteUrlOff() ) {
url = new URL( new URL( formatter.getBaseURL(), relativeUrlStr ), urlStr );
}
url = new URL( formatter.getBaseURL(), urlStr.startsWith( "/" ) ? urlStr.substring( 1 ) : urlStr );
input = formatter.getReaderFactory().openStream( url );
}
Expand Down
10 changes: 5 additions & 5 deletions test/com/inet/lib/less/RewriteUrls/off.css
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
.rule2 {
url1: url('../image.jpg');
url2: url('../image.jpg');
url2: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
url3: url('subfolder1/image.jpg');
url4: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
url5: url('../DoesNotExists.jpg');
url6: url('subfolder1/DoesNotExists.jpg');
url7: url('../../main.jpg');
url8: url('../../main.jpg');
url8: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
url9: url('http://test.com');
}
.rule1 {
url1: url('image.jpg');
url2: url('image.jpg');
url2: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
url3: url('subfolder1/image.jpg');
url4: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
url5: url('DoesNotExists.jpg');
url6: url('subfolder1/DoesNotExists.jpg');
url7: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
url8: url('../main.jpg');
url9: url('../main.jpg');
url9: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
url10: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
url11: url('/main.jpg');
url12: url('subfolder2/sub.jpg');
url13: url('subfolder2/sub.jpg');
url13: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
}

1 comment on commit 2752b71

@jcompagner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that i find this a problem, but i just want to mention it that this change does "break" the compatibility with the lessc compiler
The lessc compiler will not be able to find in "off" mode the data for those give urls to make a data: url

Now "off" and "local" are way more similar (or "off" and "all") because all the data-uri stuff are all the same over all of them. The only difference is the normal urls based

Please sign in to comment.