Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fast_transfer_file API 分发文件,如果源文件中的文件名包含空格,会报错 #812 #1649

Open
wants to merge 5 commits into
base: 3.5.x
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,16 @@ private boolean validateFileSystemPath(String path) {
if (StringUtils.isBlank(path)) {
return false;
}
if (path.indexOf(' ') != -1) {
return false;
}
Pattern p1 = Pattern.compile("(//|\\\\)+");
Matcher m1 = p1.matcher(path);
if (m1.matches()) {
return false;
}

Pattern p2 = Pattern.compile("^[a-zA-Z]:(/|\\\\).*");//windows
//windows,以'字母:\\'开头,不包含非法字符
Pattern p2 = Pattern.compile("^[a-zA-Z]:((/|\\\\)([^<>:\"/\\\\|?*])*)*$");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 可以抽取为公共方法,方便复用
  2. 基本方法需要补充单元测试案例
  3. windows路径规范参考官方的,看下是否一致。https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats

Matcher m2 = p2.matcher(path);

if (!m2.matches()) { //非windows
if (!m2.matches()) { //非windows,除了/之外所有字符都合法
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

实现与注释不一致

if (path.charAt(0) == '/') {
return !path.contains("\\\\");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,16 @@ private boolean validateFileSystemPath(String path) {
if (StringUtils.isBlank(path)) {
return false;
}
if (path.indexOf(' ') != -1) {
return false;
}
Pattern p1 = Pattern.compile("(//|\\\\)+");
Matcher m1 = p1.matcher(path);
if (m1.matches()) {
return false;
}

Pattern p2 = Pattern.compile("^[a-zA-Z]:(/|\\\\).*");//windows
//windows,以'字母:\\'开头,不包含非法字符
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

重复方法

Pattern p2 = Pattern.compile("^[a-zA-Z]:((/|\\\\)([^<>:\"/\\\\|?*])*)*$");
Matcher m2 = p2.matcher(path);

if (!m2.matches()) { //非windows
if (!m2.matches()) { //非windows,除了/之外所有字符都合法
if (path.charAt(0) == '/') {
return !path.contains("\\\\");
} else {
Expand Down