From af3b039d31d56017169608bb85ab65fde6a0aa0d Mon Sep 17 00:00:00 2001 From: Abel Yagubyan Date: Fri, 23 Oct 2026 16:13:45 -0400 Subject: [PATCH] fix(native): preserve whitespace in Mach-O segment and section names (#6842) Fixes #6818 Co-authored-by: Abelo9996 Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> --- src/native/parsers/otool.ts | 9 ++++ .../native/nativeLoadKinds.golden.test.ts | 44 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/native/parsers/otool.ts b/src/native/parsers/otool.ts index cf685ac41d..37ade5ac33 100644 --- a/src/native/parsers/otool.ts +++ b/src/native/parsers/otool.ts @@ -507,10 +507,19 @@ const TEXT_FIELDS = /^(?:segname|sectname|string #\d+)$/u; */ const OFFSET_STRING_FIELD = /^(name|path) (.* \(offset \d+\))$/u; +/** + * otool prints segment and section names as ` %.16s`: one separator + * space, then the fixed-width name, whose own leading and trailing whitespace + * belongs to the Mach-O value. + */ +const MACHO_NAME_FIELD = /^(segname|sectname)(?: (.*))?$/u; + const parseField = (rawLine: string): readonly [string, string] | undefined => { const offsetString = OFFSET_STRING_FIELD.exec(rawLine.trimStart()); if (offsetString?.[1] !== undefined && offsetString[2] !== undefined) return [offsetString[1], offsetString[2]]; + const name = MACHO_NAME_FIELD.exec(rawLine.trimStart()); + if (name?.[1] !== undefined) return [name[1], name[2] ?? ""]; // otool prints each linker option as `string #n