Skip to content

Commit

Permalink
Allow periods and hyphens in bucket names (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Apr 1, 2024
1 parent 8ae5bff commit 204e4ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 3 additions & 4 deletions hsds/util/domainUtil.py
Expand Up @@ -304,8 +304,7 @@ def getLimits():

def isValidBucketName(bucket):
"""
Check whether the given bucket name contains only
alphanumeric characters and underscores
Check whether the given bucket name is valid
"""
is_valid = True

Expand All @@ -316,8 +315,8 @@ def isValidBucketName(bucket):
if len(bucket) < 1:
is_valid = False

# Bucket names can consist only of alphanumeric characters and underscores
if not re.fullmatch("[a-zA-Z0-9_]+", bucket):
# Bucket names can consist only of alphanumeric characters, underscores, dots, and hyphens
if not re.fullmatch("[a-zA-Z0-9_\\.\\-]+", bucket):
is_valid = False

return is_valid
7 changes: 6 additions & 1 deletion tests/unit/domain_util_test.py
Expand Up @@ -129,7 +129,6 @@ def testIsValidBucketName(self):
self.assertFalse(isValidBucketName("bucket\""))
self.assertFalse(isValidBucketName("bucket "))
self.assertFalse(isValidBucketName("bucket>"))
self.assertFalse(isValidBucketName(".bucket"))
self.assertFalse(isValidBucketName(""))

self.assertTrue(isValidBucketName("bucket"))
Expand All @@ -138,6 +137,12 @@ def testIsValidBucketName(self):
self.assertTrue(isValidBucketName("_"))
self.assertTrue(isValidBucketName("___1234567890___"))

self.assertTrue(isValidBucketName("bucket"))
self.assertTrue(isValidBucketName("buck.et"))
self.assertTrue(isValidBucketName("bucket1"))
self.assertTrue(isValidBucketName("buck-et"))
self.assertTrue(isValidBucketName("bucket-1.bucket1-.1"))


if __name__ == "__main__":
# setup test files
Expand Down

0 comments on commit 204e4ae

Please sign in to comment.