Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/143449.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 143449
summary: Fix CSV-escaped quotes rendering in generated ES|QL docs examples
area: ES|QL
type: bug
issues: []

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1896,8 +1896,17 @@ private String renderTableLine(String[] columns) {
if (i > 0) {
sb.append(" | ");
}
String cell = columns[i].trim();
// Unescape RFC 4180 CSV-quoted values that contain doubled quotes ("").
// In CSV spec results, a value like "{""key"":""val""}" uses outer " as field delimiters
// and "" as escaped ". We strip the delimiters and unescape so JSON renders correctly
// in docs (e.g. {"key":"value"} instead of {""key"":""value""}).
// Simple quoted values like "POINT(...)" have no "" inside and are left unchanged.
if (cell.startsWith("\"") && cell.endsWith("\"") && cell.substring(1, cell.length() - 1).contains("\"\"")) {
cell = cell.substring(1, cell.length() - 1).replace("\"\"", "\"");
}
// Some cells have regex content (see CATEGORIZE), so we need to escape this
sb.append(columns[i].trim().replaceAll("\\.\\*", ".\\\\*"));
sb.append(cell.replaceAll("\\.\\*", ".\\\\*"));
}
return sb.append(" |\n").toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,34 @@ public void testRenderingExampleResultRaw() throws IOException {
assertThat(results, equalTo(expectedResults));
}

/**
* Verify that RFC 4180 CSV-quoted values with doubled quotes are properly unescaped,
* so JSON strings render correctly in docs instead of showing {""key"":""value""}.
*/
public void testRenderingExampleResultCsvJsonUnescaping() throws IOException {
String expectedResults = """
| log:keyword | severity:keyword |
| --- | --- |
| {"severity":"ERROR","body":"Payment processing failed"} | ERROR |
""";
String results = docs.loadExample("json_extract.csv-spec", "json_extract-result");
assertThat(results, equalTo(expectedResults));
}

/**
* Verify that simple quoted values (no doubled quotes inside) are preserved as-is.
* Only values with "" (RFC 4180 escaping) should be unescaped.
*/
public void testRenderingExampleResultSimpleQuotesPreserved() throws IOException {
String expectedResults = """
| wkt:keyword | pt:geo_point |
| --- | --- |
| "POINT(42.97109630194 14.7552534413725)" | POINT(42.97109630194 14.7552534413725) |
""";
String results = docs.loadExample("spatial.csv-spec", "to_geopoint-str-result");
assertThat(results, equalTo(expectedResults));
}

public void testRenderingExampleRaw2() throws IOException {
String expectedExample = """
ROW n=1
Expand Down
Loading