fix(native): normalize otool line endings and strip plist JSON BOM (#533)

This commit is contained in:
morluto
2026-10-05 15:28:31 +08:00
committed by GitHub
parent 0f77ada55e
commit 3e4d4d93fd
3 changed files with 50 additions and 2 deletions
+12 -1
View File
@@ -44,8 +44,19 @@ interface ParsedLoadCommands {
readonly flags: Set<string>;
}
/**
* otool emits LF, but a capture replayed from another host or toolchain can
* carry CRLF. The section/command boundaries below match a bare `\n`, so a
* stray `\r` would swallow the terminator and silently empty `sections` while
* leaking section fields into the command. Normalizing once at the boundary
* keeps every parser below working on one line ending.
*/
const normalizeLineEndings = (output: string): string =>
output.replaceAll("\r\n", "\n");
/** Parse stable fields from `otool -l`, preserving unknown command fields. */
export const parseOtoolLoadCommands = (output: string) => {
export const parseOtoolLoadCommands = (raw: string) => {
const output = normalizeLineEndings(raw);
const headerTokens = parseHeaderTokens(output);
const state = createLoadCommandState(headerTokens);
for (const block of output.split(/(?=Load command \d+)/u))