fix relative image path bug and Less support#22
fix relative image path bug and Less support#22benoit-ponsero wants to merge 13 commits intodirkmc:masterfrom
Conversation
|
Hi Benoit, |
|
Hello, i change to read the full line whereas one byte. I don't know why commands.pyc was committed. Maybe it was updated when i run build-module. You can ignore this file |
|
Hi Benoit, Could you please fix this code and include a set of tests that demonstrate that it works for all scenarios? |
|
hello, i setup a test application with different test case, you can get it at : https://github.com/benoit-ponsero/testpress module.press=../press |
|
Ok thanks. Could you also push your code so that I can see the fix |
|
i dit not fix anything. i think you missconfigured your url in css. |
|
I think maybe there's a bug in the repath method: private static String repath(String cssFileUrl, String url) {
String[] parts = url.split("\\.\\./");
int len = parts.length;
String finalurl = "";
String[] urlparts = cssFileUrl.split("/");
for (int n = 0; n < urlparts.length - len; n++) {
finalurl += urlparts[n] + "/";
}
finalurl += parts[len - 1];
return finalurl;
}It looks to me like it takes the part of the css file path up to the last slash, and appends the part of the url after the last ../ So for example: |
|
i just test it and the result is : /web/public/images/sprite.png as it should be. |
|
Ok I think it's almost right. The only problem is when you have things like public class Test {
public static void main(String[] args) {
String[][] tests = {
{"/web/myproj/public/stylesheets/test.css", "test.png", "/web/myproj/public/stylesheets/test.png"},
{"/web/myproj/public/stylesheets/test.css", "../up.png", "/web/myproj/public/up.png"},
{"/web/myproj/public/stylesheets/test.css", "../../up2.png", "/web/myproj/up2.png"},
{"/web/myproj/public/stylesheets/test.css", "../../../up3.png", "/web/up3.png"},
{"/web/myproj/public/stylesheets/test.css", "../somedir/../../level1.png", "/web/myproj/public/level1.png"},
{"/web/myproj/public/stylesheets/test.css", "../../somedir/../level2.png", "/web/myproj/level2.png"},
{"/web/myproj/public/stylesheets/test.css", "../../somedir/../somedir/../level2.png", "/web/myproj/level2.png"},
{"/web/myproj/public/stylesheets/test.css", "subdir/testsubdir.png", "/web/myproj/public/stylesheets/subdir/testsubdir.png"},
{"/web/myproj/public/stylesheets/test.css", "subdir/subdir2/testsubdir2.png", "/web/myproj/public/stylesheets/subdir/subdir2/testsubdir2.png"},
{"/web/myproj/public/stylesheets/test.css", "subdir/subdir2/../subdir2up.png", "/web/myproj/public/stylesheets/subdir/subdir2up.png"},
{"/web/myproj/public/stylesheets/test.css", "subdir/subdir2/../../subdir2up2.png", "/web/myproj/public/stylesheets/subdir2up2.png"},
{"/web/myproj/public/stylesheets/test.css", "subdir/subdir2/../../../subdir2up3.png", "/web/myproj/public/subdir2up3.png"},
};
for (String[] test : tests) {
String cssFile = test[0];
String url = test[1];
String expected = test[2];
String result = repath(cssFile, url);
System.out.println("css: " + cssFile);
System.out.println("url: " + url);
System.out.println("=> " + result);
if(expected.equals(result)) {
System.out.println("[OK]\n");
} else {
System.out.println("exp: " + expected);
System.out.println("[Failed]\n");
}
}
}
private static String repath(String cssFileUrl, String url) {
String[] parts = url.split("\\.\\./");
int len = parts.length;
String finalurl = "";
String[] urlparts = cssFileUrl.split("/");
for (int n = 0; n < urlparts.length - len; n++) {
finalurl += urlparts[n] + "/";
}
finalurl += parts[len - 1];
return finalurl;
}
} |
|
I would love to see these changes merged to master. I'm having conflicts with less 0.9.1 and there is no way I'm giving up .less usage. |
Hello,
rewrite url() or src= to set the correct path when css are in different folders that the css generated.