Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Enhancements

### Bug Fixes
- Create a WildcardMatcher.NONE when creating a WildcardMatcher with an empty string ([#5694](https://github.com/opensearch-project/security/pull/5694))

### Refactoring

Expand Down
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
Copy Markdown

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
Copy Markdown
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