Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 265180 Details for
Bug 505737
Passing in a search term that is unknown to the server causes it to default to a file search
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Updated Java server fix (with tests)
org.eclipse.orion.server.unknown.term.patch (text/plain), 5.55 KB, created by
Michael Rennie
on 2016-11-03 14:28:42 EDT
(
hide
)
Description:
Updated Java server fix (with tests)
Filename:
MIME Type:
Creator:
Michael Rennie
Created:
2016-11-03 14:28:42 EDT
Size:
5.55 KB
patch
obsolete
>diff --git a/bundles/org.eclipse.orion.server.search/src/org/eclipse/orion/internal/server/search/FileGrepper.java b/bundles/org.eclipse.orion.server.search/src/org/eclipse/orion/internal/server/search/FileGrepper.java >index f1bcdd2..c5ba8d9 100644 >--- a/bundles/org.eclipse.orion.server.search/src/org/eclipse/orion/internal/server/search/FileGrepper.java >+++ b/bundles/org.eclipse.orion.server.search/src/org/eclipse/orion/internal/server/search/FileGrepper.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2014, 2015 IBM Corporation and others. >+ * Copyright (c) 2014, 2016 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 >@@ -195,6 +195,9 @@ > */ > public List<SearchResult> search(SearchOptions options) throws SearchException { > List<SearchResult> files = new LinkedList<SearchResult>(); >+ if(!options.isFileContentsSearch() && options.getFilenamePattern() == null) { >+ return files; >+ } > try { > for (SearchScope scope : options.getScopes()) { > currentWorkspace = scope.getWorkspace(); >@@ -252,11 +255,13 @@ > * @return the correct search term. > */ > private String undoLuceneEscape(String searchTerm) { >- String specialChars = "+-&|!(){}[]^\"~:\\"; >- for (int i = 0; i < specialChars.length(); i++) { >- String character = specialChars.substring(i, i + 1); >- String escaped = "\\" + character; >- searchTerm = searchTerm.replaceAll(Pattern.quote(escaped), character); >+ if(searchTerm != null) { >+ String specialChars = "+-&|!(){}[]^\"~:\\"; >+ for (int i = 0; i < specialChars.length(); i++) { >+ String character = specialChars.substring(i, i + 1); >+ String escaped = "\\" + character; >+ searchTerm = searchTerm.replaceAll(Pattern.quote(escaped), character); >+ } > } > return searchTerm; > } >diff --git a/bundles/org.eclipse.orion.server.search/src/org/eclipse/orion/internal/server/search/SearchServlet.java b/bundles/org.eclipse.orion.server.search/src/org/eclipse/orion/internal/server/search/SearchServlet.java >index b1cbf30..c4ea115 100644 >--- a/bundles/org.eclipse.orion.server.search/src/org/eclipse/orion/internal/server/search/SearchServlet.java >+++ b/bundles/org.eclipse.orion.server.search/src/org/eclipse/orion/internal/server/search/SearchServlet.java >@@ -130,6 +130,9 @@ > } > } > } >+ } else if(term.indexOf(":") > -1) { >+ //unknown search term, ignore >+ continue; > } else { > //decode the term string now > try { >@@ -162,13 +165,16 @@ > JSONObject resultsJSON = new JSONObject(); > JSONObject responseJSON = new JSONObject(); > try { >- resultsJSON.put("numFound", files.size()); > resultsJSON.put("start", 0); >- > JSONArray docs = new JSONArray(); >- for (SearchResult file : files) { >- docs.put(file.toJSON(contextPath)); >+ int found = 0; >+ if(files != null) { >+ found = files.size(); >+ for (SearchResult file : files) { >+ docs.put(file.toJSON(contextPath)); >+ } > } >+ resultsJSON.put("numFound", found); > resultsJSON.put("docs", docs); > // Add to parent JSON > JSONObject responseHeader = new JSONObject(); >diff --git a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/search/SearchTest.java b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/search/SearchTest.java >index c45083e..eaf2391 100644 >--- a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/search/SearchTest.java >+++ b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/search/SearchTest.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2012, 2015 IBM Corporation and others. >+ * Copyright (c) 2012, 2016 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 >@@ -35,6 +35,7 @@ > import org.json.JSONArray; > import org.json.JSONException; > import org.json.JSONObject; >+import org.junit.Assert; > import org.junit.Before; > import org.junit.BeforeClass; > import org.junit.Test; >@@ -155,6 +156,48 @@ > } > > /** >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=505737 >+ * @throws Exception >+ */ >+ @Test >+ public void testUnknownTerm() throws Exception { >+ try { >+ JSONObject result = doSearch("Unknown:'hello'"); >+ assertNoMatch(result); >+ } catch(NullPointerException npe) { >+ Assert.fail("No NPE should have been thrown"); >+ } >+ } >+ >+ /** >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=505737 >+ * @throws Exception >+ */ >+ @Test >+ public void testUnknownTermMixedTail() throws Exception { >+ try { >+ JSONObject result = doSearch("Name:'Foo'+NameLower:'foo'+Unknown:'hello'"); >+ assertNoMatch(result); >+ } catch(NullPointerException npe) { >+ Assert.fail("No NPE should have been thrown"); >+ } >+ } >+ >+ /** >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=505737 >+ * @throws Exception >+ */ >+ @Test >+ public void testUnknownTermMixedMid() throws Exception { >+ try { >+ JSONObject result = doSearch("Name:'Foo'+Unknown:'hello'+NameLower:'foo'"); >+ assertNoMatch(result); >+ } catch(NullPointerException npe) { >+ Assert.fail("No NPE should have been thrown"); >+ } >+ } >+ >+ /** > * Tests finding search results on a part of a word. > */ > @Test
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 505737
: 265180