fix(bin): properly escape arguments (#788)

This commit is contained in:
Simon Chan 2025-08-25 14:13:03 +08:00 committed by GitHub
parent f3f5be0b1a
commit 2f57a86a80
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 106 additions and 79 deletions

View file

@ -1,5 +1,3 @@
import { splitCommand } from "@yume-chan/adb";
import type { Cmd } from "./service.js";
export function resolveFallback(
@ -31,13 +29,7 @@ export function serializeAbbService(
): string {
checkCommand(command);
// `abb` mode doesn't use `sh -c` to execute to command,
// so it doesn't accept escaped arguments.
// `splitCommand` can be used to remove the escaping,
// each item in `command` must be a single argument.
const newCommand = command.map((arg) => splitCommand(arg)[0]!);
// `abb` mode uses `\0` as the separator, allowing space in arguments.
// The last `\0` is required for older versions of `adb`.
return `${prefix}:${newCommand.join("\0")}\0`;
return `${prefix}:${command.join("\0")}\0`;
}