diff --git a/docs/content/manual/dev/manual.yml b/docs/content/manual/dev/manual.yml index 12e1837cf2..cceb8b821e 100644 --- a/docs/content/manual/dev/manual.yml +++ b/docs/content/manual/dev/manual.yml @@ -2151,9 +2151,15 @@ sections: * `@csv`: - The input must be an array, and it is rendered as CSV - with double quotes for strings, and quotes escaped by - repetition. + The input must be an array, and it is rendered as comma + separated CSV with double quotes for strings, and quotes + escaped by repetition. + + * `@scsv`: + + The input must be an array, and it is rendered as semicolon + separated CSV with double quotes for strings, and quotes + escaped by repetition. * `@tsv`: diff --git a/jq.1.prebuilt b/jq.1.prebuilt index 8c21b18680..dc6bb93fd3 100644 --- a/jq.1.prebuilt +++ b/jq.1.prebuilt @@ -2340,7 +2340,13 @@ The inverse of \fB@uri\fR, applies percent\-decoding, by mapping all \fB%XX\fR s \fB@csv\fR: . .IP -The input must be an array, and it is rendered as CSV with double quotes for strings, and quotes escaped by repetition\. +The input must be an array, and it is rendered as comma separated CSV with double quotes for strings, and quotes escaped by repetition\. +. +.TP +\fB@ssv\fR: +. +.IP +The input must be an array, and it is rendered as semicolon separated CSV with double quotes for strings, and quotes escaped by repetition\. . .TP \fB@tsv\fR: diff --git a/src/builtin.c b/src/builtin.c index 7695fbb9aa..e5501fca9c 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -558,7 +558,7 @@ static jv f_format(jq_state *jq, jv input, jv fmt) { } else if (!strcmp(fmt_s, "text")) { jv_free(fmt); return f_tostring(jq, input); - } else if (!strcmp(fmt_s, "csv") || !strcmp(fmt_s, "tsv")) { + } else if (!strcmp(fmt_s, "csv") || !strcmp(fmt_s, "scsv") || !strcmp(fmt_s, "tsv")) { const char *quotes, *sep, *escapings; const char *msg; if (!strcmp(fmt_s, "csv")) { @@ -566,6 +566,11 @@ static jv f_format(jq_state *jq, jv input, jv fmt) { quotes = "\""; sep = ","; escapings = "\"\"\"\0"; + } else if (!strcmp(fmt_s, "scsv")) { + msg = "cannot be scsv-formatted, only array"; + quotes = "\""; + sep = ";"; + escapings = "\"\"\"\0"; } else { msg = "cannot be tsv-formatted, only array"; assert(!strcmp(fmt_s, "tsv")); diff --git a/tests/jq.test b/tests/jq.test index e25558d2d4..9d31a68316 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -61,11 +61,12 @@ null null "interpolation" -@text,@json,([1,.]|@csv,@tsv),@html,(@uri|.,@urid),@sh,(@base64|.,@base64d) +@text,@json,([1,.]|@csv,@scsv,@tsv),@html,(@uri|.,@urid),@sh,(@base64|.,@base64d) "!()<>&'\"\t" "!()<>&'\"\t" "\"!()<>&'\\\"\\t\"" "1,\"!()<>&'\"\"\t\"" +"1;\"!()<>&'\"\"\t\"" "1\t!()<>&'\"\\t" "!()<>&'"\t" "%21%28%29%3C%3E%26%27%22%09"