Skip to content

[Bug]: Literal NUL bytes make TypeScript sources opaque to Git review #347

Closed

Description

@jimhoyd

Runtime revision and environment

origin/main at 7972185, source inspection on macOS. No runtime behavior was executed.

Minimal reproduction

Several tracked TypeScript files embed a literal U+0000 byte inside regex character classes intended to reject control characters. For example:

git show origin/main:src/site.ts | file -
# /dev/stdin: data
git show origin/main:src/site.ts | tr -cd "\000" | wc -c
# 4

The same scan finds one literal NUL in each of:

  • src/policies/security.ts
  • src/scaffold.ts
  • packages/ui/test/theme.test.ts

src/site.ts therefore appears as Bin in Git diffs, including the recent site.notFound change, rather than exposing a reviewable TypeScript patch.

Relevant output

The bytes occur only in regex ranges such as [^\s<NUL>-\x1f\x7f] and /<NUL>-\x1f\x7f/, so they appear to be an accidental source encoding choice rather than required data. Node accepts the source, but Git classifies every affected file as binary.

Replace literal control bytes with textual JavaScript escapes (for example \u0000-\u001f\u007f) while preserving regex semantics and adversarial control-character tests. Add a lightweight repository guard that rejects literal NUL bytes in tracked source/test text files, so future code reviews stay textual.

Activity

  1. added
    bug
    in-progress
    on Sep 20, 2026
  2. jimhoyd commented on Sep 20, 2026

    @jimhoyd
    CollaboratorAuthor

    Progress: an agent has started on this; a PR will be linked here when it opens.

  3. jimhoyd commented on Sep 21, 2026

    @jimhoyd
    CollaboratorAuthor

    Progress: PR #351 opened: literal NUL bytes replaced by \x00 escapes in src/site.ts, src/policies/security.ts, src/scaffold.ts and packages/ui/test/theme.test.ts, proven equivalent over all non-surrogate code units, plus scripts/nul-scan.ts wired into npm run check.

  4. removed
    in-progress
    on Sep 21, 2026
  5. jimhoyd commented on Sep 21, 2026

    @jimhoyd
    CollaboratorAuthor

    Fixed in #351: the literal NUL bytes in src/site.ts, src/policies/security.ts, src/scaffold.ts and packages/ui/test/theme.test.ts are now \x00 escapes (regexes checked identical over all non-surrogate UTF-16 code units; lone surrogates were not covered), and scripts/nul-scan.ts, run by npm run check, fails on a literal NUL in any tracked text-extension file. The same character classes also held literal U+001F and U+007F, which are escaped too.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions