提交 e4bd2c60 authored 作者: Thomas Mueller's avatar Thomas Mueller

The user home directory prefix (~) is now only expanded when followed by a slash…

The user home directory prefix (~) is now only expanded when followed by a slash or backslash, or standing alone.
上级 122380dd
...@@ -57,7 +57,20 @@ public class FileSystemDisk extends FileSystem { ...@@ -57,7 +57,20 @@ public class FileSystemDisk extends FileSystem {
* @return the native file name * @return the native file name
*/ */
protected String translateFileName(String fileName) { protected String translateFileName(String fileName) {
if (fileName != null && fileName.startsWith("~")) { return expandUserHomeDirectory(fileName);
}
/**
* Expand '~' to the user home directory. It is only be expanded if the ~ stands alone, or is followed by / or \.
*
* @param fileName the file name
* @return the native file name
*/
public static String expandUserHomeDirectory(String fileName) {
if (fileName == null) {
return null;
}
if (fileName.startsWith("~") && (fileName.length() == 1 || fileName.startsWith("~/") || fileName.startsWith("~\\"))) {
String userDir = SysProperties.USER_HOME; String userDir = SysProperties.USER_HOME;
fileName = userDir + fileName.substring(1); fileName = userDir + fileName.substring(1);
} }
......
...@@ -15,8 +15,6 @@ import java.util.ArrayList; ...@@ -15,8 +15,6 @@ import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import org.h2.constant.SysProperties;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.util.New; import org.h2.util.New;
...@@ -230,11 +228,7 @@ public class FileSystemZip extends FileSystem { ...@@ -230,11 +228,7 @@ public class FileSystemZip extends FileSystem {
if (idx >= 0) { if (idx >= 0) {
fileName = fileName.substring(0, idx); fileName = fileName.substring(0, idx);
} }
if (fileName.startsWith("~")) { return FileSystemDisk.expandUserHomeDirectory(fileName);
String userDir = SysProperties.USER_HOME;
fileName = userDir + fileName.substring(1);
}
return fileName;
} }
private String getEntryName(String fileName) { private String getEntryName(String fileName) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论