Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Ratz2021-01-15 13:45:36 +0000
committerSebastian Ratz2021-01-15 14:30:36 +0000
commit2abcf7451cac96ef70f0667cb04b7251a8f4ea42 (patch)
treee1d5f2fe500d4160c8956d9eb507074222fec059
parent714eec740cef3a71b4704366d5baaf4c01ac7190 (diff)
downloadeclipse.platform.ui-2abcf7451cac96ef70f0667cb04b7251a8f4ea42.tar.gz
eclipse.platform.ui-2abcf7451cac96ef70f0667cb04b7251a8f4ea42.tar.xz
eclipse.platform.ui-2abcf7451cac96ef70f0667cb04b7251a8f4ea42.zip
Bug 570390 - trim trailing whitespace in patternY20210115-1200I20210116-0340I20210115-1810
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/misc/TextMatcher.java5
-rw-r--r--tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/filteredtree/TextMatcherTest.java12
2 files changed, 15 insertions, 2 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/misc/TextMatcher.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/misc/TextMatcher.java
index ae19839ad6f..6b07140a2f1 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/misc/TextMatcher.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/misc/TextMatcher.java
@@ -28,6 +28,7 @@ import org.eclipse.core.text.StringMatcher;
* The precise rules are:
* </p>
* <ul>
+ * <li>Leading and trailing whitespace in the pattern is ignored.</li>
* <li>If the full pattern matches the full text, the match succeeds.</li>
* <li>If the full pattern matches a single word of the text, the match
* succeeds.</li>
@@ -57,7 +58,7 @@ public final class TextMatcher {
* @throws IllegalArgumentException if {@code pattern == null}
*/
public TextMatcher(String pattern, boolean ignoreCase, boolean ignoreWildCards) {
- full = new StringMatcher(pattern, ignoreCase, ignoreWildCards);
+ full = new StringMatcher(pattern.trim(), ignoreCase, ignoreWildCards);
parts = splitPattern(pattern, ignoreCase, ignoreWildCards);
}
@@ -67,7 +68,7 @@ public final class TextMatcher {
if (pat.isEmpty()) {
return Collections.emptyList();
}
- String[] subPatterns = pattern.split("\\s+"); //$NON-NLS-1$
+ String[] subPatterns = pat.split("\\s+"); //$NON-NLS-1$
if (subPatterns.length <= 1) {
return Collections.emptyList();
}
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/filteredtree/TextMatcherTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/filteredtree/TextMatcherTest.java
index 3e6ca63ffbf..7f817e79951 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/filteredtree/TextMatcherTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/filteredtree/TextMatcherTest.java
@@ -64,6 +64,12 @@ public class TextMatcherTest {
assertFalse(new TextMatcher("h?hner", false, true).match("hahn henne hühnerhof küken huhn"));
assertFalse(new TextMatcher("h*hner", false, true).match("hahn henne hühnerhof küken huhn"));
assertFalse(new TextMatcher("hühner", false, true).match("hahn henne hühnerhof küken huhn"));
+
+ // Bug 570390: Pattern starting/ending with whitespace should still match
+ assertTrue(new TextMatcher("hahn ", false, false).match("hahn henne hühnerhof küken huhn"));
+ assertTrue(new TextMatcher("huhn ", false, false).match("hahn henne hühnerhof küken huhn"));
+ assertTrue(new TextMatcher(" hahn", false, false).match("hahn henne hühnerhof küken huhn"));
+ assertTrue(new TextMatcher(" huhn", false, false).match("hahn henne hühnerhof küken huhn"));
}
@Test
@@ -80,6 +86,12 @@ public class TextMatcherTest {
assertTrue(new TextMatcher("huhn hühner", false, false).match("hahn henne hühnerhof küken huhn"));
assertTrue(new TextMatcher("huhn hühner", false, true).match("hahn henne hühner küken huhn"));
assertTrue(new TextMatcher("huhn hühner", false, true).match("hahn henne hühnerhof küken huhn"));
+
+ // Bug 570390: Pattern starting/ending with whitespace should still match
+ assertTrue(new TextMatcher("huhn hahn ", false, false).match("hahn henne hühnerhof küken huhn"));
+ assertTrue(new TextMatcher("hahn huhn ", false, false).match("hahn henne hühnerhof küken huhn"));
+ assertTrue(new TextMatcher(" huhn hahn", false, false).match("hahn henne hühnerhof küken huhn"));
+ assertTrue(new TextMatcher(" hahn huhn", false, false).match("hahn henne hühnerhof küken huhn"));
}
@Test

Back to the top