[Bug 36059] [lang] Wrong length check in StrTokenizer.StringMatcher. From Oliver Heger <oliver.heger@t-online.de>.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@230565 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2005-08-06 18:53:57 +00:00
parent 1225f4309c
commit 707e1a4a0b
2 changed files with 17 additions and 1 deletions

View File

@ -1238,7 +1238,7 @@ static final class StringMatcher implements Matcher {
*/
public int isMatch(char[] text, int textLen, int pos) {
int len = chars.length;
if (pos + len >= textLen) {
if (pos + len > textLen) {
return 0;
}
for (int i = 0; i < chars.length; i++, pos++) {

View File

@ -379,6 +379,22 @@ public void testReset() {
assertEquals("f", tok.next());
assertEquals("g", tok.next());
}
public void testStringMatcher() {
// build test fixture
char[] data = new char[26];
for(int i = 0; i < data.length; i++) {
data[i] = (char) (i + 'a');
}
// perform tests
StrTokenizer.Matcher matcher = new StrTokenizer.StringMatcher("z");
for(int i = 0; i < data.length - 1; i++) {
assertEquals(0, matcher.isMatch(data, data.length, i));
}
assertEquals(1, matcher.isMatch(data, data.length, data.length - 1));
// test bad pos argument.
assertEquals(0, matcher.isMatch(data, data.length, data.length +100));
}
public void testTSV() {
this.testXSVAbc(StrTokenizer.getTSVInstance(TSV_SIMPLE_FIXTURE));