normalizeCommand
normalizeCommand(
command):string
Defined in: _worktrees/docs-release/gaunt-sloth/packages/core/src/core/shell/normalize.ts:87
Normalize a command string before dangerous-pattern matching.
Steps (each closes an obfuscation bypass):
- strip ANSI escape sequences (CSI / OSC / lone-escape),
- drop null bytes,
- Unicode NFKC fold (fullwidth
rm→rm, etc.), - canonicalize every line ending (CRLF / lone CR) to a bare
\n, - collapse shell backslash-escapes (
r\m→rm,\-rf→-rf), - drop empty-string literals that split tokens (
r''m/r""m→rm), - fold runs of HORIZONTAL whitespace (spaces/tabs) to single spaces,
- collapse each run of line breaks to a single
\n— which survives, because a line break is a command separator, not padding (EXT-55) — and trim the ends.
EXT-55: the last two steps used to be one \s+ → ' ' fold, which erased the command boundary
and let ls -la\nrm -rf / be read as the single command ls. A line break now reaches every
consumer intact, exactly like ;. Leading/trailing breaks are still trimmed, so the very
common "npm test\n" tool argument remains ONE command and keeps matching the allow-list.
A backslash before a line break (a shell line continuation) is deliberately NOT joined: folding
it away would re-open the same hole for ls \<newline>rm -rf /. Keeping the boundary makes such
a command categorically ambiguous, which costs a prompt, not a failure.
This is intentionally lossy: the normalized form is ONLY used for detection, never for execution (the original command is what runs).
Parameters
Section titled “Parameters”command
Section titled “command”string
Returns
Section titled “Returns”string