This is an automated email from the ASF dual-hosted git repository.

gaul pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jclouds.git

commit 6670c556d7637d2d3301ca3cbe8ba60fdd08d67c
Author: jixinchi <jixin...@bytedance.com>
AuthorDate: Mon Apr 15 11:27:51 2024 +0800

    add unit test for Filesystem BlobKey and ContainerName validator
---
 .../validators/internal/FilesystemBlobKeyValidatorImpl.java    |  5 ++++-
 .../validators/internal/FilesystemBlobKeyValidatorTest.java    |  6 ++++++
 .../internal/FilesystemContainerNameValidatorTest.java         | 10 ++++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git 
a/apis/filesystem/src/main/java/org/jclouds/filesystem/predicates/validators/internal/FilesystemBlobKeyValidatorImpl.java
 
b/apis/filesystem/src/main/java/org/jclouds/filesystem/predicates/validators/internal/FilesystemBlobKeyValidatorImpl.java
index 563968edcc..f53cb11021 100644
--- 
a/apis/filesystem/src/main/java/org/jclouds/filesystem/predicates/validators/internal/FilesystemBlobKeyValidatorImpl.java
+++ 
b/apis/filesystem/src/main/java/org/jclouds/filesystem/predicates/validators/internal/FilesystemBlobKeyValidatorImpl.java
@@ -20,6 +20,9 @@ import 
org.jclouds.filesystem.predicates.validators.FilesystemBlobKeyValidator;
 
 import com.google.inject.Singleton;
 
+import java.io.File;
+import java.util.Arrays;
+
 /**
  * Validates name for filesystem container blob keys implementation
  *
@@ -38,7 +41,7 @@ public class FilesystemBlobKeyValidatorImpl extends 
FilesystemBlobKeyValidator {
         //blobkey cannot start with / (or \ in Windows) character
         if (name.startsWith("\\") || name.startsWith("/"))
             throw new IllegalArgumentException("Blob key '" + name + "' cannot 
start with \\ or /");
-        if (name.contains("../"))
+        if (Arrays.asList(name.split(File.separator.equals("\\") ? "\\\\" : 
File.separator)).contains(".."))
             throw new IllegalArgumentException("Blob key '" + name + "' cannot 
contain ../");
     }
 
diff --git 
a/apis/filesystem/src/test/java/org/jclouds/filesystem/predicates/validators/internal/FilesystemBlobKeyValidatorTest.java
 
b/apis/filesystem/src/test/java/org/jclouds/filesystem/predicates/validators/internal/FilesystemBlobKeyValidatorTest.java
index b06254f542..e3e1436edb 100644
--- 
a/apis/filesystem/src/test/java/org/jclouds/filesystem/predicates/validators/internal/FilesystemBlobKeyValidatorTest.java
+++ 
b/apis/filesystem/src/test/java/org/jclouds/filesystem/predicates/validators/internal/FilesystemBlobKeyValidatorTest.java
@@ -36,6 +36,7 @@ public class FilesystemBlobKeyValidatorTest {
 
         validator.validate("all.img");
         validator.validate("all" + File.separator + "is" + File.separator + "" 
+ "ok");
+        validator.validate("all" + File.separator + "is" + File.separator + 
".." + "ok");
     }
 
     @Test
@@ -51,6 +52,11 @@ public class FilesystemBlobKeyValidatorTest {
             validator.validate(File.separator + "is" + File.separator + "" + 
"ok");
             fail("Blob key value incorrect, but was not recognized");
         } catch (IllegalArgumentException e) {}
+
+        try {
+            validator.validate("all" + File.separator + ".." + File.separator 
+ "ok");
+            fail("Blob key value incorrect, but was not recognized");
+        } catch (IllegalArgumentException e) {}
     }
 
 
diff --git 
a/apis/filesystem/src/test/java/org/jclouds/filesystem/predicates/validators/internal/FilesystemContainerNameValidatorTest.java
 
b/apis/filesystem/src/test/java/org/jclouds/filesystem/predicates/validators/internal/FilesystemContainerNameValidatorTest.java
index c8bdd61de6..668dc6870c 100644
--- 
a/apis/filesystem/src/test/java/org/jclouds/filesystem/predicates/validators/internal/FilesystemContainerNameValidatorTest.java
+++ 
b/apis/filesystem/src/test/java/org/jclouds/filesystem/predicates/validators/internal/FilesystemContainerNameValidatorTest.java
@@ -60,6 +60,16 @@ public class FilesystemContainerNameValidatorTest {
             validator.validate("all" + File.separator + "is" + File.separator);
             fail("Container name value incorrect, but was not recognized");
         } catch (IllegalArgumentException e) {}
+
+        try {
+            validator.validate(".");
+            fail("Container name value incorrect, but was not recognized");
+        } catch (IllegalArgumentException e) {}
+
+        try {
+            validator.validate("..");
+            fail("Container name value incorrect, but was not recognized");
+        } catch (IllegalArgumentException e) {}
     }
 
 

Reply via email to