HADOOP-17518. Update the regex to A-Z (#5669). Contributed by Nishtha Shah.

Signed-off-by: Ayush Saxena <ayushsaxena@apache.org>
This commit is contained in:
NishthaShah 2023-05-20 06:21:13 +05:30 committed by GitHub
parent 0914b3e792
commit 5272ed8670
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -106,13 +106,13 @@ public class Check {
return list;
}
private static final String IDENTIFIER_PATTERN_STR = "[a-zA-z_][a-zA-Z0-9_\\-]*";
private static final String IDENTIFIER_PATTERN_STR = "[a-zA-Z_][a-zA-Z0-9_\\-]*";
private static final Pattern IDENTIFIER_PATTERN = Pattern.compile("^" + IDENTIFIER_PATTERN_STR + "$");
/**
* Verifies a value is a valid identifier,
* <code>[a-zA-z_][a-zA-Z0-9_\-]*</code>, up to a maximum length.
* <code>[a-zA-Z_][a-zA-Z0-9_\-]*</code>, up to a maximum length.
*
* @param value string to check if it is a valid identifier.
* @param maxLen maximun length.

View File

@ -116,6 +116,16 @@ public class TestCheck extends HTestCase {
Check.validIdentifier("1", 1, "");
}
@Test(expected = IllegalArgumentException.class)
public void validIdentifierInvalid4() throws Exception {
Check.validIdentifier("`a", 2, "");
}
@Test(expected = IllegalArgumentException.class)
public void validIdentifierInvalid5() throws Exception {
Check.validIdentifier("[a", 2, "");
}
@Test
public void checkGTZeroGreater() {
assertEquals(Check.gt0(120, "test"), 120);

View File

@ -36,7 +36,7 @@ import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
public final class ResourceTypesTestHelper {
private static final Pattern RESOURCE_VALUE_AND_UNIT_PATTERN =
Pattern.compile("(\\d+)([A-za-z]*)");
Pattern.compile("(\\d+)([A-Za-z]*)");
private ResourceTypesTestHelper() {}