-
Notifications
You must be signed in to change notification settings - Fork 201
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
base: 3.5.x
Are you sure you want to change the base?
Conversation
|
||
Pattern p2 = Pattern.compile("^[a-zA-Z]:(/|\\\\).*");//windows | ||
//windows,以'字母:\\'开头,不包含非法字符 | ||
Pattern p2 = Pattern.compile("^[a-zA-Z]:((/|\\\\)([^<>:\"/\\\\|?*])*)*$"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 可以抽取为公共方法,方便复用
- 基本方法需要补充单元测试案例
- 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,除了/之外所有字符都合法 |
There was a problem hiding this comment.
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,以'字母:\\'开头,不包含非法字符 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
重复方法
另外,参数的校验可以优化下,使用Spring validation,可以参考下其他地方的实现 |
# 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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要补充更多的测试用例,如一些比较常见的:
- 根目录 /
- /tmp/
- /tmp/test/../test.log
assertThat(FilePathValidateUtil.validateFileSystemAbsolutePath("data/test_2022-04-12.apk")).isFalse(); | ||
assertThat(FilePathValidateUtil.validateFileSystemAbsolutePath("///")).isFalse(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- /// 是合法linux路径
- 多个/的场景需要加入测试用例,比如/tmp////, /tmp//test/
* @param path | ||
* @return boolean | ||
*/ | ||
private static boolean validateWindowsFileSystemAbsolutePath(String path) { | ||
// DOS设备 | ||
String pattern = "^\\\\\\\\.\\\\.+|\\\\\\\\\\?\\\\.+"; |
There was a problem hiding this comment.
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” 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. |
No description provided.