Skip to content

Commit 62cf3aa

Browse files
authored
SOLR-17110: Fix JacksonJsonWriter to properly quote uuid values in json query response (#2367)
1 parent 2fe98d9 commit 62cf3aa

File tree

3 files changed

+63
-7
lines changed

3 files changed

+63
-7
lines changed

solr/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ Bug Fixes
150150
* SOLR-14892: Queries with shards.info and shards.tolerant can yield multiple null keys in place of shard names
151151
(Mathieu Marie, David Smiley)
152152

153+
* SOLR-17110: Fixed JacksonJsonWriter to properly quote uuid values in json query response (Andrey Bozhko via Eric Pugh)
154+
153155
* SOLR-17209: Fix NullPointerException in QueryComponent (Vincent Primault via Eric Pugh)
154156

155157
* SOLR-17113: Correct how `/replication?command=details` describes errors in backup operations. (Przemyslaw Ciezkowski via Christine Poerschke and Jason Gerlowski)

solr/core/src/java/org/apache/solr/response/JacksonJsonWriter.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ public WriterImpl(
8383
@Override
8484
public void writeResponse() throws IOException {
8585
if (wrapperFunction != null) {
86-
writeStr(null, wrapperFunction + "(", false);
86+
writeStrRaw(null, wrapperFunction + "(");
8787
}
8888
super.writeNamedList(null, rsp.getValues());
8989
if (wrapperFunction != null) {
90-
writeStr(null, ")", false);
90+
writeStrRaw(null, ")");
9191
}
9292
gen.close();
9393
}
@@ -128,11 +128,7 @@ public void writeNull(String name) throws IOException {
128128

129129
@Override
130130
public void writeStr(String name, String val, boolean needsEscaping) throws IOException {
131-
if (needsEscaping) {
132-
gen.writeString(val);
133-
} else {
134-
gen.writeRawValue(val);
135-
}
131+
gen.writeString(val);
136132
}
137133

138134
@Override

solr/core/src/test/org/apache/solr/response/JSONWriterTest.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,62 @@ public void testWfrJSONWriter() throws IOException {
346346
jsonEq(expected, buf.toString());
347347
req.close();
348348
}
349+
350+
@Test
351+
public void testResponseValuesProperlyQuoted() throws Exception {
352+
assertU(
353+
adoc(
354+
"id",
355+
"1",
356+
"name",
357+
"John Doe",
358+
"cat",
359+
"foo\"b'ar",
360+
"uuid",
361+
"6e2fb55b-dd42-4e2d-84ca-71a599403aa3",
362+
"bsto",
363+
"true",
364+
"isto",
365+
"42",
366+
"amount",
367+
"100,USD",
368+
"price",
369+
"3.14",
370+
"severity",
371+
"High",
372+
"dateRange",
373+
"[2024-03-01 TO 2024-03-31]",
374+
"timestamp",
375+
"2024-03-20T12:34:56Z"));
376+
assertU(commit());
377+
378+
String expected =
379+
"{\n"
380+
+ " \"response\":{\n"
381+
+ " \"numFound\":1,\n"
382+
+ " \"start\":0,\n"
383+
+ " \"numFoundExact\":true,\n"
384+
+ " \"docs\":[{\n"
385+
+ " \"id\":\"1\",\n"
386+
+ " \"name\":[\"John Doe\"],\n"
387+
+ " \"cat\":[\"foo\\\"b'ar\"],\n"
388+
+ " \"uuid\":[\"6e2fb55b-dd42-4e2d-84ca-71a599403aa3\"],\n"
389+
+ " \"bsto\":[true],\n"
390+
+ " \"isto\":[42],\n"
391+
+ " \"amount\":\"100,USD\",\n"
392+
+ " \"price\":3.14,\n"
393+
+ " \"severity\":\"High\",\n"
394+
+ " \"dateRange\":[\"[2024-03-01 TO 2024-03-31]\"],\n"
395+
+ " \"timestamp\":\"2024-03-20T12:34:56Z\"\n"
396+
+ " }]\n"
397+
+ " }\n"
398+
+ "}";
399+
400+
String fl = "id,name,cat,uuid,bsto,isto,amount,price,severity,dateRange,timestamp";
401+
var req = req("q", "id:*", "fl", fl, "wt", "json", "omitHeader", "true");
402+
try (req) {
403+
String response = h.query("/select", req);
404+
jsonEq(expected, response);
405+
}
406+
}
349407
}

0 commit comments

Comments
 (0)