Skip to content

Commit

Permalink
增加用于校验文件夹名的合法性
Browse files Browse the repository at this point in the history
  • Loading branch information
PengyuDeng committed Aug 22, 2024
1 parent 4172f16 commit 135a574
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jetlinks.community.io.file;

import com.alibaba.excel.util.StringUtils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufUtil;
Expand Down Expand Up @@ -38,6 +37,7 @@
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.function.Function;
import java.util.regex.Pattern;

@Slf4j
public class ClusterFileManager implements FileManager {
Expand All @@ -58,6 +58,7 @@ public class ClusterFileManager implements FileManager {
*/
public static final String API_PATH_CONFIG_NAME = "paths";
public static final String API_PATH_CONFIG_KEY = "base-path";
private static final Pattern LEGAL_DIRECTORY_NAME_PATTERN = Pattern.compile("^[^\\\\/:*?\"<>|]{1,255}$");

private final FileProperties properties;

Expand Down Expand Up @@ -170,8 +171,8 @@ public Mono<FileInfo> saveFile(String name, Flux<DataBuffer> stream, FileOption.

@Override
public Mono<FileInfo> saveFile(String name, String folder, Flux<DataBuffer> stream, FileOption... options) {
if (folder.contains("/")) {
return Mono.error(new BusinessException("error.folder_cannot_contains:/"));
if (!LEGAL_DIRECTORY_NAME_PATTERN.matcher(folder).matches()) {
return Mono.error(new BusinessException("error.folder_name_is_invalid"));
}
return doSaveFile(name, folder, stream, options);
}
Expand Down

0 comments on commit 135a574

Please sign in to comment.