Skip to content

Commit d62c7e6

Browse files
committed
Handling a missed corner case
HAndling the case when the path is '~' only.
1 parent 419d5f0 commit d62c7e6

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

biojava-core/src/main/java/org/biojava/nbio/core/util/FileDownloadUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public static String toUnixPath(String path) {
200200
public static String expandUserHome(String file) {
201201
// replace any / with the proper separator (/ or \ for Linux and Windows respectively).
202202
file = file.replaceAll("/", "\\"+File.separator); //The "\\" is to escape the separator if needed.
203-
if (file.startsWith("~" + File.separator)) {
203+
if (file.startsWith("~") && (file.length() == 1 || File.separator.equals(file.substring(1, 2)))) {
204204
file = System.getProperty("user.home") + file.substring(1);
205205
}
206206
return file;

biojava-core/src/test/java/org/biojava/nbio/core/util/FileDownloadUtilsTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ void unixPathReturnedUnchanged(){
131131
class ExpandUserHome {
132132
String currUserHome = System.getProperty("user.home");
133133
@Test
134+
void minimalPath (){
135+
String path="~";
136+
assertEquals(currUserHome, FileDownloadUtils.expandUserHome(path));
137+
}
138+
@Test
134139
void simplePath (){
135140
String path="~/sequence.gb";
136141
assertEquals(currUserHome+File.separator+"sequence.gb", FileDownloadUtils.expandUserHome(path));

0 commit comments

Comments
 (0)