You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ep...@apache.org on 2024/03/28 19:21:16 UTC

(solr) branch branch_9x updated: SOLR-17110: Fix JacksonJsonWriter to properly quote uuid values in json query response (#2367)

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

epugh 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 fcdad0ee63f SOLR-17110: Fix JacksonJsonWriter to properly quote uuid values in json query response (#2367)
fcdad0ee63f is described below

commit fcdad0ee63fa8d37a64b409135fb9d652623c724
Author: Andrey Bozhko <an...@gmail.com>
AuthorDate: Thu Mar 28 14:20:01 2024 -0500

    SOLR-17110: Fix JacksonJsonWriter to properly quote uuid values in json query response (#2367)
---
 solr/CHANGES.txt                                   |  2 +
 .../apache/solr/response/JacksonJsonWriter.java    | 10 ++--
 .../org/apache/solr/response/JSONWriterTest.java   | 58 ++++++++++++++++++++++
 3 files changed, 63 insertions(+), 7 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 8c997e19bef..a639de7149a 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -68,6 +68,8 @@ Bug Fixes
 * SOLR-14892: Queries with shards.info and shards.tolerant can yield multiple null keys in place of shard names
   (Mathieu Marie, David Smiley)
 
+* SOLR-17110: Fixed JacksonJsonWriter to properly quote uuid values in json query response (Andrey Bozhko via Eric Pugh)
+
 * SOLR-17209: Fix NullPointerException in QueryComponent (Vincent Primault via Eric Pugh)
 
 * SOLR-17113: Correct how `/replication?command=details` describes errors in backup operations.  (Przemyslaw Ciezkowski via Christine Poerschke and Jason Gerlowski)
diff --git a/solr/core/src/java/org/apache/solr/response/JacksonJsonWriter.java b/solr/core/src/java/org/apache/solr/response/JacksonJsonWriter.java
index 415d1f9169b..3ab9121c37d 100644
--- a/solr/core/src/java/org/apache/solr/response/JacksonJsonWriter.java
+++ b/solr/core/src/java/org/apache/solr/response/JacksonJsonWriter.java
@@ -83,11 +83,11 @@ public class JacksonJsonWriter extends BinaryResponseWriter {
     @Override
     public void writeResponse() throws IOException {
       if (wrapperFunction != null) {
-        writeStr(null, wrapperFunction + "(", false);
+        writeStrRaw(null, wrapperFunction + "(");
       }
       super.writeNamedList(null, rsp.getValues());
       if (wrapperFunction != null) {
-        writeStr(null, ")", false);
+        writeStrRaw(null, ")");
       }
       gen.close();
     }
@@ -128,11 +128,7 @@ public class JacksonJsonWriter extends BinaryResponseWriter {
 
     @Override
     public void writeStr(String name, String val, boolean needsEscaping) throws IOException {
-      if (needsEscaping) {
-        gen.writeString(val);
-      } else {
-        gen.writeRawValue(val);
-      }
+      gen.writeString(val);
     }
 
     @Override
diff --git a/solr/core/src/test/org/apache/solr/response/JSONWriterTest.java b/solr/core/src/test/org/apache/solr/response/JSONWriterTest.java
index 7d6e324a418..6d45634da78 100644
--- a/solr/core/src/test/org/apache/solr/response/JSONWriterTest.java
+++ b/solr/core/src/test/org/apache/solr/response/JSONWriterTest.java
@@ -346,4 +346,62 @@ public class JSONWriterTest extends SolrTestCaseJ4 {
     jsonEq(expected, buf.toString());
     req.close();
   }
+
+  @Test
+  public void testResponseValuesProperlyQuoted() throws Exception {
+    assertU(
+        adoc(
+            "id",
+            "1",
+            "name",
+            "John Doe",
+            "cat",
+            "foo\"b'ar",
+            "uuid",
+            "6e2fb55b-dd42-4e2d-84ca-71a599403aa3",
+            "bsto",
+            "true",
+            "isto",
+            "42",
+            "amount",
+            "100,USD",
+            "price",
+            "3.14",
+            "severity",
+            "High",
+            "dateRange",
+            "[2024-03-01 TO 2024-03-31]",
+            "timestamp",
+            "2024-03-20T12:34:56Z"));
+    assertU(commit());
+
+    String expected =
+        "{\n"
+            + "  \"response\":{\n"
+            + "    \"numFound\":1,\n"
+            + "    \"start\":0,\n"
+            + "    \"numFoundExact\":true,\n"
+            + "    \"docs\":[{\n"
+            + "      \"id\":\"1\",\n"
+            + "      \"name\":[\"John Doe\"],\n"
+            + "      \"cat\":[\"foo\\\"b'ar\"],\n"
+            + "      \"uuid\":[\"6e2fb55b-dd42-4e2d-84ca-71a599403aa3\"],\n"
+            + "      \"bsto\":[true],\n"
+            + "      \"isto\":[42],\n"
+            + "      \"amount\":\"100,USD\",\n"
+            + "      \"price\":3.14,\n"
+            + "      \"severity\":\"High\",\n"
+            + "      \"dateRange\":[\"[2024-03-01 TO 2024-03-31]\"],\n"
+            + "      \"timestamp\":\"2024-03-20T12:34:56Z\"\n"
+            + "    }]\n"
+            + "  }\n"
+            + "}";
+
+    String fl = "id,name,cat,uuid,bsto,isto,amount,price,severity,dateRange,timestamp";
+    var req = req("q", "id:*", "fl", fl, "wt", "json", "omitHeader", "true");
+    try (req) {
+      String response = h.query("/select", req);
+      jsonEq(expected, response);
+    }
+  }
 }