Skip to content

Commit

Permalink
DefaultHistory.matchPatterns is broken, fixes #635
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Jan 15, 2021
1 parent 5d4add1 commit 9a49718
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2018, the original author or authors.
* Copyright (c) 2002-2021, the original author or authors.
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
Expand Down Expand Up @@ -401,6 +401,8 @@ protected boolean matchPatterns(String patterns, String line) {
sb.append('|');
} else if (ch == '*') {
sb.append('.').append('*');
} else {
sb.append(ch);
}
}
return line.matches(sb.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2016, the original author or authors.
* Copyright (c) 2002-2021, the original author or authors.
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
Expand All @@ -25,6 +25,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;

/**
Expand Down Expand Up @@ -176,4 +177,15 @@ public void testAddHistoryLine() throws IOException {
assertTrue(e.getMessage().startsWith("Bad history file syntax!"));
}
}

@Test
public void testMatchPatterns() {
DefaultHistory defaultHistory = new DefaultHistory();
assertFalse(defaultHistory.matchPatterns("foo", "bar"));
assertTrue(defaultHistory.matchPatterns("foo", "foo"));
assertTrue(defaultHistory.matchPatterns("foo*", "foobar"));
assertTrue(defaultHistory.matchPatterns("foo:bar", "bar"));
assertFalse(defaultHistory.matchPatterns("foo*", "bar"));
}

}

0 comments on commit 9a49718

Please sign in to comment.