Fixing FileID.getFileName when dealing with opaque URIs
This commit is contained in:
parent
ff48442fa0
commit
0485fdf2f3
|
@ -55,7 +55,21 @@ public class FileID
|
|||
{
|
||||
if (uri == null)
|
||||
return "";
|
||||
String path = uri.getPath();
|
||||
if (uri.isOpaque())
|
||||
{
|
||||
return getFileName(uri.getSchemeSpecificPart());
|
||||
}
|
||||
return getFileName(uri.getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last segment of a String path returning it as the filename
|
||||
*
|
||||
* @param path the string path to look for the filename
|
||||
* @return The last segment of the path
|
||||
*/
|
||||
public static String getFileName(String path)
|
||||
{
|
||||
if (path == null || "/".equals(path))
|
||||
return "";
|
||||
int idx = path.lastIndexOf('/');
|
||||
|
|
|
@ -106,6 +106,7 @@ public class FileIDTest
|
|||
Arguments.of(URI.create("file:zed/"), ""),
|
||||
Arguments.of(URI.create("file:///path/to/test.txt"), "test.txt"),
|
||||
Arguments.of(URI.create("file:///path/to/dir/"), ""),
|
||||
Arguments.of(URI.create("jar:file:///home/user/libs/jetty-server-12.jar!/org/eclipse/jetty/server/jetty-dir.css"), "jetty-dir.css"),
|
||||
Arguments.of(URI.create("http://eclipse.org/jetty/"), ""),
|
||||
Arguments.of(URI.create("http://eclipse.org/jetty/index.html"), "index.html"),
|
||||
Arguments.of(URI.create("http://eclipse.org/jetty/docs.html?query=val#anchor"), "docs.html")
|
||||
|
|
Loading…
Reference in New Issue