Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucas Bullen2018-01-12 15:26:30 +0000
committerNoopur Gupta2018-01-15 10:10:22 +0000
commit56d367cbdef9fbb2bf130076ff757d80de5971ac (patch)
treef0de78ee5aace275d2f292b4dbd3d3e558289e8e
parent66136c2373e1dabcd3f7d0f60e5dcd66a5075984 (diff)
downloadeclipse.platform.ui-56d367cbdef9fbb2bf130076ff757d80de5971ac.tar.gz
eclipse.platform.ui-56d367cbdef9fbb2bf130076ff757d80de5971ac.tar.xz
eclipse.platform.ui-56d367cbdef9fbb2bf130076ff757d80de5971ac.zip
Bug 529451 - Open Resource dialog throws SIOOBE
- Escapes all regex characters - properly deal with '/' for folder searches Change-Id: I9804ee7c2dc62de22d9b289d51679530c95c1690 Signed-off-by: Lucas Bullen <lbullen@redhat.com>
-rw-r--r--bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/FilteredResourcesSelectionDialog.java37
-rw-r--r--tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dialogs/ResourceItemLabelTest.java15
2 files changed, 36 insertions, 16 deletions
diff --git a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/FilteredResourcesSelectionDialog.java b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/FilteredResourcesSelectionDialog.java
index 1e8912d9393..d8306e338bc 100644
--- a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/FilteredResourcesSelectionDialog.java
+++ b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/FilteredResourcesSelectionDialog.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -18,6 +18,7 @@ import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
@@ -637,7 +638,11 @@ public class FilteredResourcesSelectionDialog extends
}
IResource resource = (IResource) element;
- String searchFieldString = ((Text) getPatternControl()).getText();
+ String searchFieldString = escapeRegexCharacters(((Text) getPatternControl()).getText());
+ int fileNameIndex = searchFieldString.lastIndexOf('/');
+ if (fileNameIndex != -1 && fileNameIndex != searchFieldString.length() - 1) {
+ searchFieldString = searchFieldString.substring(fileNameIndex + 1);
+ }
String resourceName = resource.getName();
Styler boldStyler = new Styler() {
@Override
@@ -677,7 +682,7 @@ public class FilteredResourcesSelectionDialog extends
if (matching.indexOf('?') == -1 && matching.indexOf('*') == -1) {
matching = String.join("*", matching.split("(?=[A-Z0-9])")) + "*"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
} else {
- matching = matching.toLowerCase();
+ matching = matching.toLowerCase().replaceAll("\\\\\\\\", "\\\\"); //$NON-NLS-1$ //$NON-NLS-2$
string = string.toLowerCase();
}
@@ -705,19 +710,8 @@ public class FilteredResourcesSelectionDialog extends
restart = true;
break;
}
- int regionIndex = 0;
+ int regionIndex = region.replace("\\\\", "1").replace("\\", "").length(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
currentIndex += startlocation;
- for (char regionChar : region.toCharArray()) {
- if (regionChar == '\\') {
- continue;
- }
- regionIndex++;
- if (regionChar == '.' && regionIndex != 1) {
- positions.add(new Position(currentIndex, regionIndex - 1));
- currentIndex += regionIndex;
- regionIndex = 0;
- }
- }
positions.add(new Position(currentIndex, regionIndex));
currentIndex += regionIndex;
usedRegions++;
@@ -735,6 +729,19 @@ public class FilteredResourcesSelectionDialog extends
return matcher.find() ? matcher.start() : -1;
}
+ private String escapeRegexCharacters(String inputString) {
+ final List<Character> metaCharacters = Arrays.asList('\\', '^', '$', '{', '}', '[', ']', '(', ')', '+', '|',
+ '<', '>', '-', '&');
+ StringBuilder output = new StringBuilder();
+ for (char character : inputString.toCharArray()) {
+ if (metaCharacters.contains(character)) {
+ output.append('\\');
+ }
+ output.append(character);
+ }
+ return output.toString();
+ }
+
@Override
public void dispose() {
provider.removeListener(this);
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dialogs/ResourceItemLabelTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dialogs/ResourceItemLabelTest.java
index db04a142060..ad78fd24ec6 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dialogs/ResourceItemLabelTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dialogs/ResourceItemLabelTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2017 Red Hat Inc. and others.
+ * Copyright (c) 2017, 2018 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -117,6 +117,19 @@ public class ResourceItemLabelTest extends UITestCase {
}
/**
+ * Tests that regex symbols do not break search
+ *
+ * @throws Exception
+ */
+ public void testBug529451() throws Exception {
+ Position[] basic = { new Position(4, 1) };
+ compareStyleRanges(basic, getStyleRanges("*$", "test$.txt"));
+
+ Position[] multiple = { new Position(0, 3), new Position(7, 9), new Position(17, 1) };
+ compareStyleRanges(multiple, getStyleRanges("^${*}[])(+|><?-", "^${skip}[])(+|><s-"));
+ }
+
+ /**
* Tests that the highlighting matches extension searches
*
* @throws Exception

Back to the top