Skip to content

Commit e85d171

Browse files
authored
Add skip bucket/region/object name validation as special usecase (#1576)
1 parent 245f63d commit e85d171

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

api/src/main/java/io/minio/BucketArgs.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ public abstract static class Builder<B extends Builder<B, A>, A extends BucketAr
3939
extends BaseArgs.Builder<B, A> {
4040
private static final Pattern BUCKET_NAME_REGEX =
4141
Pattern.compile("^[a-z0-9][a-z0-9\\.\\-]{1,61}[a-z0-9]$");
42+
protected boolean skipValidation = false;
4243

4344
protected void validateBucketName(String name) {
4445
validateNotNull(name, "bucket name");
46+
if (skipValidation) {
47+
return;
48+
}
4549

4650
if (!BUCKET_NAME_REGEX.matcher(name).find()) {
4751
throw new IllegalArgumentException(
@@ -63,7 +67,7 @@ protected void validateBucketName(String name) {
6367
}
6468

6569
private void validateRegion(String region) {
66-
if (region != null && !HttpUtils.REGION_REGEX.matcher(region).find()) {
70+
if (!skipValidation && region != null && !HttpUtils.REGION_REGEX.matcher(region).find()) {
6771
throw new IllegalArgumentException("invalid region " + region);
6872
}
6973
}
@@ -80,6 +84,12 @@ public B bucket(String name) {
8084
return (B) this;
8185
}
8286

87+
@SuppressWarnings("unchecked") // Its safe to type cast to B as B extends this class.
88+
public B skipValidation(boolean skipValidation) {
89+
this.skipValidation = skipValidation;
90+
return (B) this;
91+
}
92+
8393
@SuppressWarnings("unchecked") // Its safe to type cast to B as B extends this class.
8494
public B region(String region) {
8595
validateRegion(region);

api/src/main/java/io/minio/ObjectArgs.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public abstract static class Builder<B extends Builder<B, A>, A extends ObjectAr
4343
extends BucketArgs.Builder<B, A> {
4444
protected void validateObjectName(String name) {
4545
validateNotEmptyString(name, "object name");
46+
if (skipValidation) {
47+
return;
48+
}
4649
for (String token : name.split("/")) {
4750
if (token.equals(".") || token.equals("..")) {
4851
throw new IllegalArgumentException(

0 commit comments

Comments
 (0)