419333 treat // as an alias in path

This commit is contained in:
Greg Wilkins 2013-10-14 17:16:19 +11:00
parent 9a330dad1b
commit b8c8abae2e
3 changed files with 35 additions and 4 deletions

View File

@ -2673,8 +2673,10 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
if (a.length()>r.length()) if (a.length()>r.length())
return a.startsWith(r) && a.length()==r.length()+1 && a.endsWith("/"); return a.startsWith(r) && a.length()==r.length()+1 && a.endsWith("/");
else if (a.length()<r.length())
return r.startsWith(a) && r.length()==a.length()+1 && r.endsWith("/"); return r.startsWith(a) && r.length()==a.length()+1 && r.endsWith("/");
return a.equals(r);
} }
} }

View File

@ -228,7 +228,6 @@ public class ContextHandlerGetResourceTest
assertEquals(docroot,new File(url.toURI()).getParentFile()); assertEquals(docroot,new File(url.toURI()).getParentFile());
} }
@Test @Test
public void testTooNormal() throws Exception public void testTooNormal() throws Exception
{ {
@ -294,6 +293,23 @@ public class ContextHandlerGetResourceTest
assertNull(url); assertNull(url);
} }
@Test
public void testSlashSlash() throws Exception
{
String path="//subdir/data.txt";
Resource resource=context.getResource(path);
assertNull(resource);
URL url=context.getServletContext().getResource(path);
assertNull(url);
path="/subdir//data.txt";
resource=context.getResource(path);
assertNull(resource);
url=context.getServletContext().getResource(path);
assertNull(url);
}
@Test @Test
public void testAliasedFile() throws Exception public void testAliasedFile() throws Exception
{ {

View File

@ -109,7 +109,20 @@ public class FileResource extends Resource
File file=new File(uri); File file=new File(uri);
_file=file; _file=file;
_uri=normalizeURI(_file,uri); _uri=normalizeURI(_file,uri);
_alias=checkAlias(_file);
if (!_uri.equals(_file.toURI()) && !_uri.toString().equals(_file.toURI().toString()))
{
try
{
_alias=_file.toURI().toURL();
}
catch (MalformedURLException e)
{
throw new IllegalArgumentException(e);
}
}
else
_alias=checkAlias(_file);
} }
/* -------------------------------------------------------- */ /* -------------------------------------------------------- */
@ -394,7 +407,7 @@ public class FileResource extends Resource
{ {
try try
{ {
return _file.toURI().toURL(); return new URL(_uri);
} }
catch (MalformedURLException e) catch (MalformedURLException e)
{ {