diff --git a/api/src/main/java/io/minio/BucketArgs.java b/api/src/main/java/io/minio/BucketArgs.java index a7877eb10..c50bcdfda 100644 --- a/api/src/main/java/io/minio/BucketArgs.java +++ b/api/src/main/java/io/minio/BucketArgs.java @@ -39,9 +39,13 @@ public abstract static class Builder, A extends BucketAr extends BaseArgs.Builder { private static final Pattern BUCKET_NAME_REGEX = Pattern.compile("^[a-z0-9][a-z0-9\\.\\-]{1,61}[a-z0-9]$"); + protected boolean skipValidation = false; protected void validateBucketName(String name) { validateNotNull(name, "bucket name"); + if (skipValidation) { + return; + } if (!BUCKET_NAME_REGEX.matcher(name).find()) { throw new IllegalArgumentException( @@ -63,7 +67,7 @@ protected void validateBucketName(String name) { } private void validateRegion(String region) { - if (region != null && !HttpUtils.REGION_REGEX.matcher(region).find()) { + if (!skipValidation && region != null && !HttpUtils.REGION_REGEX.matcher(region).find()) { throw new IllegalArgumentException("invalid region " + region); } } @@ -80,6 +84,12 @@ public B bucket(String name) { return (B) this; } + @SuppressWarnings("unchecked") // Its safe to type cast to B as B extends this class. + public B skipValidation(boolean skipValidation) { + this.skipValidation = skipValidation; + return (B) this; + } + @SuppressWarnings("unchecked") // Its safe to type cast to B as B extends this class. public B region(String region) { validateRegion(region); diff --git a/api/src/main/java/io/minio/ObjectArgs.java b/api/src/main/java/io/minio/ObjectArgs.java index 60758c7ed..1d7759338 100644 --- a/api/src/main/java/io/minio/ObjectArgs.java +++ b/api/src/main/java/io/minio/ObjectArgs.java @@ -43,6 +43,9 @@ public abstract static class Builder, A extends ObjectAr extends BucketArgs.Builder { protected void validateObjectName(String name) { validateNotEmptyString(name, "object name"); + if (skipValidation) { + return; + } for (String token : name.split("/")) { if (token.equals(".") || token.equals("..")) { throw new IllegalArgumentException(