Skip to content

tuf: preserve literal newlines inside string literals during canonical JSON serialization#420

Merged
erickt merged 1 commit into
theupdateframework:developfrom
erickt:cjson
Jul 16, 2026
Merged

tuf: preserve literal newlines inside string literals during canonical JSON serialization#420
erickt merged 1 commit into
theupdateframework:developfrom
erickt:cjson

Conversation

@erickt

@erickt erickt commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

TUF uses OLPC's Canonical JSON, which is not actually JSON. One of the big differences is that the only escaped sequences in strings are " and \. So it allows literal newlines, nulls, and other byte sequences that are not allowed in regular JSON strings.

  • Replace serde_json::to_string string literal serialization inside Value::write with escape_canonical_string so control characters like newlines remain unescaped literal 0x0a bytes per OLPC canonical JSON specification.
  • Add string and object key escaping edge-case unit tests.

…l JSON serialization

TUF uses OLPC's [Canonical JSON], which is not actually JSON. One of the
big differences is that the only escaped sequences in strings are `"`
and `"`. So it allows literal newlines, nulls, and other byte sequences
that are not allowed in regular JSON strings.

- Replace serde_json::to_string string literal serialization inside
  Value::write with escape_canonical_string so control characters like
  newlines remain unescaped literal 0x0a bytes per OLPC canonical JSON
  specification.
- Add string and object key escaping edge-case unit tests.

TAG=agy
CONV=e4755785-ae11-4908-b13c-5b0db1e48498

[Canonical JSON]: theupdateframework/specification#92
@erickt
erickt merged commit b9cce03 into theupdateframework:develop Jul 16, 2026
16 checks passed
@erickt
erickt deleted the cjson branch July 16, 2026 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants