fix csvjsonarray emitting invalid JSON when label-quotes is passed - #23115
Merged
Conversation
The csvjsonarray formatter adds RRDR_OPTION_LABEL_QUOTES to the options it passes to rrdr2csv using arithmetic addition instead of bitwise OR. When the caller already passes label-quotes (redundant but legal), the addition clears the bit and carries into the next one, so the header row is emitted without quotes - [time,a,b,c] - making the entire response invalid JSON. The carried-into bit is inert at format time, so the values themselves stay correct. Reachable on /api/v1, /api/v2 and /api/v3 data queries with format=csvjsonarray and options=label-quotes, at both call sites (with and without jsonwrap).
|
Merged
stelfrag
pushed a commit
to stelfrag/netdata
that referenced
this pull request
Jul 14, 2026
Ferroin
pushed a commit
that referenced
this pull request
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
The csvjsonarray formatter adds
RRDR_OPTION_LABEL_QUOTESto the options it passes torrdr2csv()using arithmetic addition instead of bitwise OR (options + RRDR_OPTION_LABEL_QUOTES, two call sites inrrd2json.c). When the caller already passeslabel-quotes— redundant but legal, since csvjsonarray always wants quoted labels — the addition clears the bit and carries into the next one. The header row is then emitted without quotes:— making the entire response invalid JSON. The carried-into bit is inert at format time (value conversion reads the query window options, which are untouched), so the values themselves stay correct.
Reachable on
/api/v1,/api/v2and/api/v3data queries withformat=csvjsonarray&options=label-quotes, at both call sites (with and withoutjsonwrap).Fix
+→|at both sites. A repository-wide search confirms these are the only two occurrences of arithmetic onRRDR_OPTION_*bits.Validation
Red/green with a deterministic fixture (one chart, three dimensions, fixed 2023 epoch), covering both call sites:
label-quotesboth v3+jsonwrap and v1 plain responses are invalid JSON (unquoted header); without it, valid JSON with correct raw values.Related finding (not addressed here)
While validating this, a separate defect surfaced:
/api/v{2,3}/data?format=csvjsonarraywithoutsecondsemits unquoted datetime strings ([2023-11-15 00:14:20,1,2,5]) — invalid JSON regardless of this fix. v1 avoids it only because its defaults includeseconds. That needs a small contract decision (quote the dates vs default csvjsonarray tosecondson v2/v3) and will be handled separately.Summary by cubic
Fixes invalid JSON from
csvjsonarraywhen callers passlabel-quotesby using bitwise OR to keep header labels quoted./api/v1,/api/v2, and/api/v3responses are now valid JSON in this case.options | RRDR_OPTION_LABEL_QUOTESinstead ofoptions + RRDR_OPTION_LABEL_QUOTESat bothrrdr2csv()call sites insrc/web/api/formatters/rrd2json.c.label-quotesis redundantly supplied.Written for commit 7e38c70. Summary will update on new commits.