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

Conversation

liuliaozhong
Copy link
Collaborator

No description provided.


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.

实现与注释不一致

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.

重复方法

@wangyu096
Copy link
Collaborator

另外,参数的校验可以优化下,使用Spring validation,可以参考下其他地方的实现

“liuliaozhong” added 2 commits January 5, 2023 20:09
# Conflicts:
#	src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v2/impl/EsbFastPushFileResourceImpl.java
#	src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastTransferFileV3ResourceImpl.java
}
// 传统DOS
pattern = "^[A-Za-z]:\\\\[^\\\\].*";
r = Pattern.compile(pattern);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pattern不建议调用没调用一次方法就compile一次,浪费性能。可以使用private static final Pattern 先预处理

if (m.matches()) {
return true;
}
// 传统DOS
Copy link
Collaborator

Choose a reason for hiding this comment

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

传统DOS是最常见的,所以可以把这块的检查放到最前面,其他校验代码就不需要执行

*/
private static boolean validateLinuxFileSystemAbsolutePath(String path) {
String pattern = "^/([^/].*/{0,1})+";
Pattern r = Pattern.compile(pattern);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pattern不建议调用没调用一次方法就compile一次,浪费性能。可以使用private static final Pattern 先预处理

assertThat(FilePathValidateUtil.validateFileSystemAbsolutePath(":\\abc.txt")).isFalse();

// linux路径
assertThat(FilePathValidateUtil.validateFileSystemAbsolutePath("/data/test_2022-04-12.apk")).isTrue();
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. /tmp/
  3. /tmp/test/../test.log

assertThat(FilePathValidateUtil.validateFileSystemAbsolutePath("data/test_2022-04-12.apk")).isFalse();
assertThat(FilePathValidateUtil.validateFileSystemAbsolutePath("///")).isFalse();
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. /// 是合法linux路径
  2. 多个/的场景需要加入测试用例,比如/tmp////, /tmp//test/

* @param path
* @return boolean
*/
private static boolean validateWindowsFileSystemAbsolutePath(String path) {
// DOS设备
String pattern = "^\\\\\\\\.\\\\.+|\\\\\\\\\\?\\\\.+";
Copy link
Collaborator

Choose a reason for hiding this comment

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

GSE 目前只支持传统dos路径,Job需要保持一致;可以去掉DOS设备和UNC路径的判断

@liuliaozhong liuliaozhong requested review from wangyu096 and removed request for jsonwan January 9, 2023 11:45
@tencentblueking-adm
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ liuliaozhong
❌ “liuliaozhong”


“liuliaozhong” seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants