fix(native): preserve text-valued load command metadata (#520)

* fix(native): preserve text-valued load command metadata

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>

* fix(native): share numeric literal pattern between parsers

---------

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
Rudy Mizrahi Celekli
2026-10-05 14:59:30 +08:00
committed by GitHub
co-authored by morluto
parent 23c4eba5b3
commit bcfb4072f2
9 changed files with 723 additions and 5 deletions
+6 -5
View File
@@ -238,11 +238,12 @@ const permissions = (raw: string | null) => {
return { read: null, write: null, execute: null, raw };
};
/** A whole decimal or hexadecimal integer literal, with no surrounding text. */
const NUMERIC_PATTERN = /^(?:0x[a-fA-F0-9]+|\d+)$/u;
const numeric = (value: string): number | null => {
const token = value.split(/\s+/u)[0];
if (token === undefined || !/^(?:0x[a-fA-F0-9]+|\d+)$/u.test(token))
return null;
const parsed = Number.parseInt(token, token.startsWith("0x") ? 16 : 10);
if (!NUMERIC_PATTERN.test(value)) return null;
const parsed = Number.parseInt(value, value.startsWith("0x") ? 16 : 10);
return Number.isSafeInteger(parsed) && parsed >= 0 ? parsed : null;
};
@@ -275,7 +276,7 @@ const hexField = (
name: string,
): string | null => {
const value = stringField(fields, name);
if (value === null || !/^(?:0x[a-fA-F0-9]+|\d+)$/u.test(value)) return null;
if (value === null || !NUMERIC_PATTERN.test(value)) return null;
return `0x${BigInt(value).toString(16)}`;
};