String containing NUL is written but can't be read back

Open
#7 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
swift
Domain
build-system

Research direction

Start at jsonRepresentation() and the JSONSerialization reader configured with .json5Allowed; reproduce the NUL round trip from the example on the referenced main revision. Resolve whether NUL is invalid or the reader should accept the writer's escaped form, then add coverage for the chosen behavior and verify other string fields.

Written by the indexing model from the issue text.

Description

A string with a NUL in it gets written, but the library can't read the file back:

var project = try XCSchema.Project(jsonRepresentation: Data(#"{"default-configuration":"Debug","localizations":{"development":"en"},"files":[]}"#.utf8))
project.buildSettings["FOO"] = .string("a\u{0}b")
let data = try project.jsonRepresentation()        // succeeds
_ = try XCSchema.Project(jsonRepresentation: data)  // throws "The data couldn't be read because it isn't in the correct format."

The writer escapes the NUL as a JSON unicode escape. The reader uses JSONSerialization with .json5Allowed, and Foundation's JSON5 scanner rejects escaped nulls ("Unsupported escaped null"), though plain JSON mode accepts them. Any string field hits this.

If NUL isn't meant to be allowed, jsonRepresentation() should throw instead of writing the file.

main @ c132630, macOS 26, Swift 6.3.3

Dominant language
Swift
Stars
384
Forks
12
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apple/xcode-project-format

All issues in apple/xcode-project-format

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.