Skip to content

Commit

Permalink
0000862: Wildcard matches in sym_trigger match more than they should
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Oct 18, 2012
1 parent c9daf4d commit d7419b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
16 changes: 11 additions & 5 deletions symmetric-util/src/main/java/org/jumpmind/util/FormatUtils.java
Expand Up @@ -152,17 +152,23 @@ public static boolean isWildCardMatch(String text, String pattern) {
// is desired, a simpler character based splitting can be done.
String[] cards = pattern.split("\\" + WILDCARD);

// Iterate over the cards.
for (String card : cards) {
int idx = text.indexOf(card);
for(int i = 0; i < cards.length; i++) {
String card = cards[i];

boolean foundToken = false;
if (i == 0 && !pattern.startsWith("*")) {
foundToken = text.startsWith(card);
} else {
foundToken = text.indexOf(card) != -1;
}

// Card not detected in the text.
if (idx == -1) {
if (!foundToken) {
return !match;
}

// Move ahead, towards the right of the text.
text = text.substring(idx + card.length());
text = text.substring(text.indexOf(card) + card.length());
}

return match;
Expand Down
Expand Up @@ -28,4 +28,16 @@ public void testReplaceCurrentTimestamp() {
Assert.assertEquals(afterSql, FormatUtils.replaceTokens(beforeSql, replacementTokens, false));

}

@Test
public void testIsWildcardMatch() {
Assert.assertTrue(FormatUtils.isWildCardMatch("TEST_1", "TEST_*"));
Assert.assertTrue(FormatUtils.isWildCardMatch("TEST_2", "TEST_*"));
Assert.assertTrue(FormatUtils.isWildCardMatch("TEST_TEST_TEST", "TEST_*"));
Assert.assertFalse(FormatUtils.isWildCardMatch("NOT_A_MATCH", "TEST_*"));
Assert.assertFalse(FormatUtils.isWildCardMatch("NOT_A_MATCH_TEST_1", "TEST_*"));
Assert.assertTrue(FormatUtils.isWildCardMatch("NOT_A_MATCH_TEST_1", "*TEST*"));
Assert.assertFalse(FormatUtils.isWildCardMatch("B_A", "*A*B"));
Assert.assertTrue(FormatUtils.isWildCardMatch("A_B", "*A*B"));
}
}

0 comments on commit d7419b6

Please sign in to comment.