Skip to content

Commit

Permalink
[apache#3078] feat(core): Use \\w instead of [a-zA-Z0-9_] in regexp (a…
Browse files Browse the repository at this point in the history
…pache#3110)

### What changes were proposed in this pull request?

Use \\w instead of [a-zA-Z0-9_] in regexp in Capability.java

### Why are the changes needed?

Fix: apache#3078 

### Does this PR introduce _any_ user-facing change?

N/A

### How was this patch tested?

ut

Co-authored-by: yangliwei <[email protected]>
  • Loading branch information
2 people authored and diqiu50 committed Jun 13, 2024
1 parent 596711f commit 92f849b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class DefaultCapability implements Capability {
*
* <p>$ - End of the string
*/
private static final String DEFAULT_NAME_PATTERN = "^[a-zA-Z0-9_][a-zA-Z0-9_/=-]{0,63}$";
private static final String DEFAULT_NAME_PATTERN = "^\\w[\\w/=-]{0,63}$";

@Override
public CapabilityResult columnNotNull() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ void testDefaultNameSpecification() {
CapabilityResult result = Capability.DEFAULT.specificationOnName(scope, "_name_123_/_=-");
Assertions.assertTrue(result.supported());

result = Capability.DEFAULT.specificationOnName(scope, "name_123_/_=-");
Assertions.assertTrue(result.supported());

result = Capability.DEFAULT.specificationOnName(scope, "Name_123_/_=-");
Assertions.assertTrue(result.supported());

// test for reserved name
result = Capability.DEFAULT.specificationOnName(scope, SECURABLE_ENTITY_RESERVED_NAME);
Assertions.assertFalse(result.supported());
Expand All @@ -44,6 +50,18 @@ void testDefaultNameSpecification() {
Assertions.assertFalse(result.supported());
Assertions.assertTrue(result.unsupportedMessage().contains("is illegal"));

result = Capability.DEFAULT.specificationOnName(scope, "-name_start_with-");
Assertions.assertFalse(result.supported());
Assertions.assertTrue(result.unsupportedMessage().contains("is illegal"));

result = Capability.DEFAULT.specificationOnName(scope, "/name_start_with/");
Assertions.assertFalse(result.supported());
Assertions.assertTrue(result.unsupportedMessage().contains("is illegal"));

result = Capability.DEFAULT.specificationOnName(scope, "=name_start_with=");
Assertions.assertFalse(result.supported());
Assertions.assertTrue(result.unsupportedMessage().contains("is illegal"));

// test for long name
StringBuilder longName = new StringBuilder();
for (int i = 0; i < 64; i++) {
Expand Down

0 comments on commit 92f849b

Please sign in to comment.