Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public String toString() {
};

public static WildcardMatcher from(String pattern) {
if (pattern == null) {
if (pattern == null || pattern.isBlank()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you perform a trim() on the pattern as well ?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trim() isn't necessary since isBlank() will return true if the string is only whitespace: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#isBlank()

return NONE;
} else if (pattern.equals("*")) {
return ANY;
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/opensearch/security/UtilTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public void testWildcardMatcherClasses() {
assertTrue(wc("abc").test("abc"));
assertFalse(wc("ABC").test("abc"));
assertFalse(wc(null).test("abc"));
assertFalse(wc("").test("abc"));
// Creating a WildcardMatcher with blank should create a matcher that matches nothing
assertFalse(wc("").test(""));
assertTrue(WildcardMatcher.from(null, "abc").test("abc"));
}

Expand Down
Loading