fix(native): preserve Mach-O install-name whitespace (#4979)

* fix(native): preserve whitespace in otool load-command strings

otool prints dylib install names and rpaths as `<key> %s (offset %u)`
with exactly one separator space around the recorded string. The parser
trimmed the value and stripped the offset suffix with `\s+`, so a valid
install name such as "  leading.dylib  " became "leading.dylib" in both
the dependency inventory and the raw load-command fields.

Parse these offset-suffixed string fields by their exact format and
strip only the single-space offset suffix.

Fixes #3384

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(native): verify exact Mach-O install names through CLI and MCP

---------

Co-authored-by: Bhaaraadwaj <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: morluto <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-10-23 06:02:37 +08:00
1 parent 15ec8e98db
commit 8b478d0f15
3 files changed
+174 -2

No files matched your search

+11 -1
View File
@@ -477,7 +477,17 @@ const parseFields = (block: string): ParsedFields => {
/** Names and linker options are text even when they look numeric. */
const TEXT_FIELDS = /^(?:segname|sectname|string #\d+)$/u;
/**
* otool prints load-command strings as `<key> %s (offset %u)`: exactly one
* separator space on each side of the recorded string, whose own leading and
* trailing whitespace belongs to the Mach-O value.
*/
const OFFSET_STRING_FIELD = /^(name|path) (.* \(offset \d+\))$/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]];
// otool prints each linker option as `string #n <option>`; keep the option
// exactly, including surrounding spaces, under otool's ordinal label.
const option = /^\s*(string #[1-9]\d*)(?: (.*))?$/u.exec(rawLine);
@@ -640,7 +650,7 @@ const hexField = (
};
const stripOffsetSuffix = (value: string | null): string =>
value?.replace(/\s+\(offset\s+\d+\)$/u, "") ?? "unknown";
value?.replace(/ \(offset \d+\)$/u, "") ?? "unknown";
const sectionAlignment = (raw: string | null): number | null => {
if (raw === null) return null;