From 0d282a2357720f93c73a9b346001933bb2fedb27 Mon Sep 17 00:00:00 2001 From: contra Date: Thu, 12 Mar 2026 17:52:12 -0400 Subject: [PATCH] fix: strip trailing null bytes from pbxproj before parsing Some runtimes (notably Bun) and filesystems (APFS) can produce files with trailing null byte padding. The PEG parser rejects \0 characters, causing a SyntaxError even though the actual pbxproj content is valid. Strip trailing null bytes before passing file contents to the parser. --- lib/parseJob.js | 3 +++ lib/pbxProject.js | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/lib/parseJob.js b/lib/parseJob.js index 45cbe9d..b4be754 100644 --- a/lib/parseJob.js +++ b/lib/parseJob.js @@ -26,6 +26,9 @@ var fs = require('fs'), try { fileContents = fs.readFileSync(path, 'utf-8'); + // Strip trailing null bytes that can appear from filesystem-level padding + // (e.g. Bun runtime file writes on APFS). The PEG parser rejects \0 characters. + fileContents = fileContents.replace(/\0+$/, ''); obj = parser.parse(fileContents); process.send(obj); } catch (e) { diff --git a/lib/pbxProject.js b/lib/pbxProject.js index 1d53a3e..70a9ce6 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -62,6 +62,10 @@ pbxProject.prototype.parse = function(cb) { pbxProject.prototype.parseSync = function() { var file_contents = fs.readFileSync(this.filepath, 'utf-8'); + // Strip trailing null bytes that can appear from filesystem-level padding + // (e.g. Bun runtime file writes on APFS). The PEG parser rejects \0 characters. + file_contents = file_contents.replace(/\0+$/, ''); + this.hash = parser.parse(file_contents); return this; }