Skip to content

Commit

Permalink
SOLR-17110: Fix JacksonJsonWriter to properly quote uuid values in js…
Browse files Browse the repository at this point in the history
…on query response (#2367)
  • Loading branch information
AndreyBozhko authored Mar 28, 2024
1 parent 2fe98d9 commit 62cf3aa
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 7 deletions.
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public WriterImpl(
@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();
}
Expand Down Expand Up @@ -128,11 +128,7 @@ public void writeNull(String name) throws IOException {

@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
Expand Down
58 changes: 58 additions & 0 deletions solr/core/src/test/org/apache/solr/response/JSONWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,62 @@ public void testWfrJSONWriter() throws IOException {
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);
}
}
}

0 comments on commit 62cf3aa

Please sign in to comment.