Skip to content

Commit

Permalink
Fixing FileID.getFileName when dealing with opaque URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
joakime committed Dec 21, 2022
1 parent ff48442 commit 0485fdf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,21 @@ public static String getFileName(URI uri)
{
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('/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public static Stream<Arguments> fileNameSource()
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")
Expand Down

0 comments on commit 0485fdf

Please sign in to comment.