Skip to content

Commit

Permalink
If the same resource name is in a root and sub dir then with local or
Browse files Browse the repository at this point in the history
all it should not hit the root one.

everything is the same as lessc compiler is outputitng except the
"off.css" which url15 works like the others that we do resolve it even
if it shouldn't according to lessc
Because url14 'test.jpg' is already mapping on the root image so
so url15 '../test.jpg' shouldn't be there (its above root). But we fall
back to always map it on the root anyway,
  • Loading branch information
jcompagner committed Dec 8, 2020
1 parent 2752b71 commit 96f8e2b
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/com/inet/lib/less/UrlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,15 @@ static void dataUri( CssFormatter formatter, String relativeUrlStr, final String
InputStream input = null;
try {
try {
input = formatter.getReaderFactory().openStream( formatter.getBaseURL(), urlStr, relativeUrlStr );
} catch( Exception e ) {
// 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 );
} catch( Exception e ) {
// try to do the default without rewrite, also if is a root url, remove that to see if the file can be found right besides the base less file.
input = formatter.getReaderFactory().openStream( formatter.getBaseURL(), urlStr.startsWith( "/" ) ? urlStr.substring( 1 ): urlStr, relativeUrlStr );
}
ByteArrayOutputStream buffer = new ByteArrayOutputStream();

Expand Down
4 changes: 4 additions & 0 deletions test/com/inet/lib/less/RewriteUrls/all.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@
url11: url('/main.jpg');
url12: url('subfolder1/subfolder2/sub.jpg');
url13: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
url14: url("data:image/jpeg;base64,dGhpcyBpcyBpbiB0aGUgc3ViZm9sZGVy");
url15: url("data:image/jpeg;base64,dGhpcyBpcyBpbiB0aGUgbWFpbg==");
url16: url('subfolder1/test.jpg');
url17: url('test.jpg');
}
4 changes: 4 additions & 0 deletions test/com/inet/lib/less/RewriteUrls/local.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@
url11: url('/main.jpg');
url12: url('subfolder2/sub.jpg');
url13: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
url14: url("data:image/jpeg;base64,dGhpcyBpcyBpbiB0aGUgc3ViZm9sZGVy");
url15: url("data:image/jpeg;base64,dGhpcyBpcyBpbiB0aGUgbWFpbg==");
url16: url('test.jpg');
url17: url('test.jpg');
}
4 changes: 4 additions & 0 deletions test/com/inet/lib/less/RewriteUrls/off.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@
url11: url('/main.jpg');
url12: url('subfolder2/sub.jpg');
url13: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
url14: url("data:image/jpeg;base64,dGhpcyBpcyBpbiB0aGUgbWFpbg==");
url15: url("data:image/jpeg;base64,dGhpcyBpcyBpbiB0aGUgbWFpbg==");
url16: url('test.jpg');
url17: url('../test.jpg');
}
4 changes: 4 additions & 0 deletions test/com/inet/lib/less/RewriteUrls/subfolder1/sub1.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
url11: url('/main.jpg');
url12: url('subfolder2/sub.jpg');
url13: data-uri('subfolder2/sub.jpg');
url14: data-uri('test.jpg');
url15: data-uri('../test.jpg');
url16: url('test.jpg');
url17: url('../test.jpg');
}
1 change: 1 addition & 0 deletions test/com/inet/lib/less/RewriteUrls/subfolder1/test.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/com/inet/lib/less/RewriteUrls/test.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 96f8e2b

Please sign in to comment.