elloralabs / webutilities

Automatically exported from code.google.com/p/webutilities
0 stars 0 forks source link

rewriting image urls fails on pre-minified code #38

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Use already minified css that references the same image repeatedly
2.Try to use the JSCSSMergeServlet, with its autocorrect css feature

I expect each time the image, "sprite.png", appears to have it replaced with 
"absolutepath/sprite.png"

Instead, the first instance of sprite.png is replaced with the absolute path of 
it as many times as the image is referenced in the file.  The rest of the image 
instances are not modified.

What version of the product are you using? On what operating system?
v0.0.5

Please provide any additional information below.
From what I can tell, the actual function buildProperPath works correctly, but 
that the way it is used in processCSSLine is incorrect.

The file I'm attaching is from the YUI library, and it is the file that 
conflicts with JSCSSMergeServlet for us.

Original issue reported on code.google.com by n...@esped.com on 29 Jun 2012 at 7:05

GoogleCodeExporter commented 8 years ago
Attached wrong file.  Try this one.

Original comment by n...@esped.com on 29 Jun 2012 at 7:08

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by rr.patil...@gmail.com on 30 Jun 2012 at 4:25

GoogleCodeExporter commented 8 years ago
I've solved this problem.
I modified the method processCSSLine of JSCSSMergeServlet class. The new method:

private String processCSSLine(ServletContext context, String contextPath, 
String cssFilePath, StringBuffer line) {
        Matcher matcher = CSS_IMG_URL_PATTERN.matcher(line);
        String cssRealPath = context.getRealPath(cssFilePath);
        while (matcher.find()) {
            String refImgPath = matcher.group(1);
            if (!isProtocolURL(refImgPath)) { //ignore absolute protocol paths
                String resolvedImgPath = refImgPath;
                if (!refImgPath.startsWith("/")) {
                    resolvedImgPath = buildProperPath(getParentPath(cssFilePath), refImgPath);
                }
                String imgRealPath = context.getRealPath(resolvedImgPath);
                int offset = line.indexOf(refImgPath);
                line.replace(
                    offset, //from
                    offset + refImgPath.length(), //to
                    contextPath + (this.turnOfUrlFingerPrinting ? resolvedImgPath : addFingerPrint(buildETagForResource(resolvedImgPath, context), resolvedImgPath))
                );
                updateReferenceMap(cssRealPath, imgRealPath);
                matcher.reset(line.subSequence(offset + refImgPath.length(), line.length()));
            }
        }
        return line.toString();
    }

Original comment by jluvi...@gmail.com on 29 Aug 2012 at 6:00

GoogleCodeExporter commented 8 years ago
Thank you!

Original comment by n...@esped.com on 29 Aug 2012 at 8:32

GoogleCodeExporter commented 8 years ago
@ jluvizon - Is it possible for you to create a pull request on github?  
https://github.com/rpatil26/webutilities

Original comment by rr.patil...@gmail.com on 30 Aug 2012 at 4:44

GoogleCodeExporter commented 8 years ago

Original comment by rr.patil...@gmail.com on 18 Oct 2012 at 2:18

GoogleCodeExporter commented 8 years ago
https://github.com/rpatil26/webutilities/commit/95c02b6f30205c32551158bcc68a5962
47bf1c2e

Original comment by rr.patil...@gmail.com on 22 Feb 2013 at 9:07