asual / lesscss-servlet

LESS Servlet - Runtime handling and optimization of less.js resources
http://www.asual.com/lesscss
Apache License 2.0
56 stars 15 forks source link

Incorrect path resolution in ResourceServlet [with fix] #6

Closed sebrichards closed 13 years ago

sebrichards commented 13 years ago

The getFile() method returns an incorrect path via getServletContext().getRealPath(path), when the servlet isn't running on a root path. This can be reproduced in Tomcat 6.

Here is the fix:

// Get the servlet's real path
String ctxRealPath = getServletContext().getRealPath("/");

// Get the servlet's relative path
String ctxRelativePath = getServletContext().getContextPath();

// Resolved resource path starts with ctx real path
String resolvedPath = ctxRealPath;

// Strip relative path from start of resource path, then append to real path
if (path.startsWith(ctxRelativePath))
    resolvedPath += path.substring(ctxRelativePath.length());
else
    resolvedPath += path;

return new File(resolvedPath);
sebrichards commented 13 years ago

Sorry - this issue appears to apply to version 1.2.11 from Maven Central. Not sure what this phantom version is all about, might have missed something!