@@ -20,6 +20,9 @@ public class RulesFunctions {
2020 private static final LazyValue<Partition> AWS_PARTITION = LazyValue.<Partition> builder()
2121 .initializer(RulesFunctions::findAwsPartition).build();
2222
23+ private static final int MAX_HOST_LABEL_SIZE = 63;
24+ private static final int MIN_BUCKET_SIZE = 3;
25+
2326 public static String substring(String value, int startIndex, int stopIndex, boolean reverse) {
2427 if (value == null) {
2528 return null;
@@ -31,6 +34,7 @@ public class RulesFunctions {
3134 }
3235
3336 for (int i = 0; i < len; i++) {
37+ // non-ascii characters (values outside of the 7bit ASCII range)
3438 if (value.charAt(i) > 127) {
3539 return null;
3640 }
@@ -83,7 +87,7 @@ public class RulesFunctions {
8387 if (i == len || hostLabel.charAt(i) == '.') {
8488 // chunk is hostLabel[start..i)
8589 int chunkLen = i - start;
86- if (chunkLen < 1 || chunkLen > 63 ) {
90+ if (chunkLen < 1 || chunkLen > MAX_HOST_LABEL_SIZE ) {
8791 return false;
8892 } else if (!isValidSingleLabel(hostLabel, start, i)) {
8993 return false;
@@ -97,7 +101,7 @@ public class RulesFunctions {
97101 // Validates a single label in s[start..end): ^[A-Za-z0-9][A-Za-z0-9\-]{0,62}$
98102 private static boolean isValidSingleLabel(String s, int start, int end) {
99103 int length = end - start;
100- if (length < 1 || length > 63 ) {
104+ if (length < 1 || length > MAX_HOST_LABEL_SIZE ) {
101105 return false;
102106 }
103107
@@ -175,7 +179,7 @@ public class RulesFunctions {
175179 public static boolean awsIsVirtualHostableS3Bucket(String hostLabel, boolean allowDots) {
176180 // Bucket names must be between 3 (min) and 63 (max) characters long.
177181 int bucketLength = hostLabel == null ? 0 : hostLabel.length();
178- if (bucketLength < 3 || bucketLength > 63 ) {
182+ if (bucketLength < MIN_BUCKET_SIZE || bucketLength > MAX_HOST_LABEL_SIZE ) {
179183 return false;
180184 }
181185
0 commit comments