Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-16019 Query parsing exception return HTTP 400 instead of 500 (#648)

Jan Høydahlcb49a7d855e2
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index a9bce19a2d5..d9e4bce4ec2 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -654,6 +654,8 @@ Bug Fixes
* SOLR-15333: Reduced spurious warn logging by AbstractSpatialPrefixTreeFieldType field properties (Steffen Moldenhauer, David Smiley, Mike Drob)
+* SOLR-16019: UTF-8 parsing errors for parameters should cause a HTTP 400 status code, not 500 (janhoy, Matthias Pigulla)
+
================== 8.11.2 ==================
Bug Fixes
diff --git a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
index 43a0e9574ea..1f0d11cced3 100644
--- a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
+++ b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
@@ -167,7 +167,7 @@ public class HttpSolrCall {
protected SolrQueryRequest solrReq = null;
private boolean mustClearSolrRequestInfo = false;
protected SolrRequestHandler handler = null;
- protected final SolrParams queryParams;
+ protected SolrParams queryParams;
protected String path;
protected Action action;
protected String coreUrl;
@@ -193,7 +193,6 @@ public class HttpSolrCall {
this.retry = retry;
this.requestType = RequestType.UNKNOWN;
req.setAttribute(HttpSolrCall.class.getName(), this);
- queryParams = SolrRequestParsers.parseQueryString(req.getQueryString());
// set a request timer which can be reused by requests if needed
req.setAttribute(SolrRequestParsers.REQUEST_TIMER_SERVLET_ATTRIBUTE, new RTimerTree());
// put the core container in request attribute
@@ -233,6 +232,8 @@ public class HttpSolrCall {
path = path.substring(0, alternate.length());
}
+ queryParams = SolrRequestParsers.parseQueryString(req.getQueryString());
+
// unused feature ?
int idx = path.indexOf(':');
if (idx > 0) {
diff --git a/solr/core/src/test/org/apache/solr/servlet/HttpSolrCallGetCoreTest.java b/solr/core/src/test/org/apache/solr/servlet/HttpSolrCallCloudTest.java
similarity index 89%
rename from solr/core/src/test/org/apache/solr/servlet/HttpSolrCallGetCoreTest.java
rename to solr/core/src/test/org/apache/solr/servlet/HttpSolrCallCloudTest.java
index 22fda8d30ef..770260a167a 100644
--- a/solr/core/src/test/org/apache/solr/servlet/HttpSolrCallGetCoreTest.java
+++ b/solr/core/src/test/org/apache/solr/servlet/HttpSolrCallCloudTest.java
@@ -23,6 +23,8 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.UnavailableException;
import javax.servlet.WriteListener;
import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
import java.util.HashSet;
import java.util.Set;
@@ -35,7 +37,7 @@ import org.eclipse.jetty.server.Response;
import org.junit.BeforeClass;
import org.junit.Test;
-public class HttpSolrCallGetCoreTest extends SolrCloudTestCase {
+public class HttpSolrCallCloudTest extends SolrCloudTestCase {
private static final String COLLECTION = "collection1";
private static final int NUM_SHARD = 3;
private static final int REPLICA_FACTOR = 2;
@@ -54,12 +56,21 @@ public class HttpSolrCallGetCoreTest extends SolrCloudTestCase {
}
@Test
- public void test() throws Exception {
+ public void testCoreChosen() throws Exception {
assertCoreChosen(NUM_SHARD, new TestRequest("/collection1/update"));
assertCoreChosen(NUM_SHARD, new TestRequest("/collection1/update/json"));
assertCoreChosen(NUM_SHARD * REPLICA_FACTOR, new TestRequest("/collection1/select"));
}
+ // https://issues.apache.org/jira/browse/SOLR-16019
+ @Test
+ public void testWrongUtf8InQ() throws Exception {
+ var baseUrl = cluster.getJettySolrRunner(0).getBaseUrl();
+ var request = new URL(baseUrl.toString() + "/" + COLLECTION + "/select?q=%C0"); // Illegal UTF-8 string
+ var connection = (HttpURLConnection) request.openConnection();
+ assertEquals(400, connection.getResponseCode());
+ }
+
private void assertCoreChosen(int numCores, TestRequest testRequest) throws UnavailableException {
JettySolrRunner jettySolrRunner = cluster.getJettySolrRunner(0);
Set<String> coreNames = new HashSet<>();