Skip to content

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

Description

@nassersala

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions