This is an automated email from the ASF dual-hosted git repository.

janhoy pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 9f5379d  SOLR-16019 Query parsing exception return HTTP 400 instead of 
500 (#648)
9f5379d is described below

commit 9f5379dc861c3fffbf1532d563ae01a0945a96d0
Author: Jan Høydahl <[email protected]>
AuthorDate: Mon Feb 21 13:27:11 2022 +0100

    SOLR-16019 Query parsing exception return HTTP 400 instead of 500 (#648)
    
    (cherry picked from commit cb49a7d855e222dfebe373a0c0dfa7c95989ea8e)
---
 solr/CHANGES.txt                                          |  2 ++
 .../src/java/org/apache/solr/servlet/HttpSolrCall.java    |  5 +++--
 ...olrCallGetCoreTest.java => HttpSolrCallCloudTest.java} | 15 +++++++++++++--
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index f3e0fc3..98a5692 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -627,6 +627,8 @@ Bug Fixes
 
 * SOLR-15558: Don't wait for zombie processes to exit when stopping. (Colvin 
Cowie)
 
+* 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 43a0e95..1f0d11c 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 22fda8d..770260a 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<>();

Reply via email to