Skip to content

Commit

Permalink
Allow TagVNotLiteralOrFilter to filter single char tag values
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Larsen <clarsen@yahoo-inc.com>
  • Loading branch information
neilfordyce authored and manolama committed May 19, 2018
1 parent 05631e8 commit 0c307b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/query/filter/TagVNotLiteralOrFilter.java
Expand Up @@ -60,9 +60,12 @@ public TagVNotLiteralOrFilter(final String tagk, final String filter,
this.case_insensitive = case_insensitive;

// we have to have at least one character.
if (filter == null || filter.length() < 2) {
if (filter == null || filter.isEmpty()) {
throw new IllegalArgumentException("Filter cannot be null or empty");
}
if (filter.length() == 1 && filter.charAt(0) == '|') {
throw new IllegalArgumentException("Filter must contain more than just a pipe");
}
final String[] split = filter.split("\\|");
if (case_insensitive) {
for (int i = 0; i < split.length; i++) {
Expand Down
7 changes: 7 additions & 0 deletions test/query/filter/TestTagVNotLiteralOrFilter.java
Expand Up @@ -122,6 +122,13 @@ public void matchSingleCaseInsensitive() throws Exception {
assertFalse(filter.match(tags).join());
assertTrue(((TagVNotLiteralOrFilter)filter).isCaseInsensitive());
}

@Test
public void matchSingleCharacterTagValue() throws Exception {
TagVFilter filter = new TagVNotLiteralOrFilter(TAGK, "c");
tags.put(TAGK, "c");
assertFalse(filter.match(tags).join());
}

@Test (expected = IllegalArgumentException.class)
public void ctorNullTagk() throws Exception {
Expand Down

0 comments on commit 0c307b0

Please sign in to comment.