fix(native): pass Swift symbols to swift-demangle as operands
`swift-demangle` parsed a symbol beginning with `-` as an option, so `-help` replaced the results with usage text and the call failed as unreadable output. A symbol containing a line feed split into extra output records, and the CRLF-tolerant parser stripped a carriage return that belonged to the final symbol. Pass the symbols after `--`, split records on the LF the demangler emits, and reject multi-line symbols in the shared CLI/MCP input schema. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
676959ecb5
commit
6c88094da4
@@ -270,7 +270,8 @@ class NativeMacOSClient implements AnalysisClient {
|
||||
const capture = await this.#run(
|
||||
"demangle_swift",
|
||||
"swift-demangle",
|
||||
["--compact", ...symbols.data],
|
||||
// `--` keeps symbols that begin with `-` from selecting demangler options.
|
||||
["--compact", "--", ...symbols.data],
|
||||
{ signal },
|
||||
);
|
||||
if (!capture.ok) return capture;
|
||||
|
||||
@@ -10,11 +10,20 @@ it.each(["ordinary name ", "ordinary\t", " "])(
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["carriage\r", "\r", "mid\rdle"])(
|
||||
"keeps carriage returns that belong to the symbol: %j",
|
||||
(input) => {
|
||||
expect(parseDemangledSymbols([input], `${input}\n`)).toEqual([
|
||||
{ input, output: input, status: "unchanged" },
|
||||
]);
|
||||
},
|
||||
);
|
||||
|
||||
it("removes only the line terminator and preserves mixed output ordering", () => {
|
||||
expect(
|
||||
parseDemangledSymbols(
|
||||
["$s4main5helloyyF", "plain "],
|
||||
"main.hello() -> ()\r\nplain \r\n",
|
||||
"main.hello() -> ()\nplain \n",
|
||||
),
|
||||
).toEqual([
|
||||
{
|
||||
|
||||
@@ -6,12 +6,16 @@ const resultSchema = z.object({
|
||||
status: z.enum(["demangled", "unchanged", "invalid"]),
|
||||
});
|
||||
|
||||
/** Preserve input ordering while parsing `swift-demangle --compact` lines. */
|
||||
/**
|
||||
* Preserve input ordering while parsing `swift-demangle --compact` lines.
|
||||
* The demangler ends each record with LF, so a carriage return belongs to the
|
||||
* symbol text.
|
||||
*/
|
||||
export const parseDemangledSymbols = (
|
||||
inputs: readonly string[],
|
||||
output: string,
|
||||
) => {
|
||||
const lines = output.replace(/\r?\n$/u, "").split(/\r?\n/u);
|
||||
const lines = output.replace(/\n$/u, "").split("\n");
|
||||
if (lines.length !== inputs.length)
|
||||
throw new TypeError("swift-demangle output count does not match input");
|
||||
return inputs.map((input, index) => {
|
||||
|
||||
Reference in New Issue
Block a user