Skip to content

Commit

Permalink
CB-5609. Added validate name for renaming s3 files (#3163)
Browse files Browse the repository at this point in the history
* CB-5609. Added validate name for renaming s3 files

* CB-5609. Refactor after review

* CB-5609. Refactor after review

* CB-5609. Refactor after review

* CB-5609. Remove symbol

---------

Co-authored-by: Daria Marutkina <125263541+dariamarutkina@users.noreply.github.com>
  • Loading branch information
DenisSinelnikov and dariamarutkina authored Dec 27, 2024
1 parent 3c73cb2 commit 92ee21d
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@
import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Web file system implementation
*/
public class WebServiceFS implements DBWServiceFS {

private static final Pattern FORBIDDEN_FILENAME_PATTERN = Pattern.compile("[%#:;№$]");

@NotNull
@Override
public FSFileSystem[] getAvailableFileSystems(@NotNull WebSession webSession, @NotNull String projectId)
Expand Down Expand Up @@ -208,6 +212,7 @@ public FSFile renameFile(
@NotNull String nodePath,
@NotNull String newName
) throws DBWebException {
validateFilename(newName);
try {
DBNPathBase node = FSUtils.getNodeByPath(webSession, nodePath);
node.rename(webSession.getProgressMonitor(), newName);
Expand Down Expand Up @@ -276,4 +281,12 @@ public boolean deleteFile(
throw new DBWebException("Failed to create folder: " + e.getMessage(), e);
}
}

private void validateFilename(@NotNull String filename) throws DBWebException {
Matcher matcher = FORBIDDEN_FILENAME_PATTERN.matcher(filename);

if (matcher.find()) {
throw new DBWebException(String.format("File %s contains forbidden symbols", filename));
}
}
}

0 comments on commit 92ee21d

Please sign in to comment.