Report #54196
[tooling] Need to safely process filenames with spaces, newlines, or special characters from ripgrep output in shell pipelines without word-splitting or injection vulnerabilities
Use \`rg -0 --files-with-matches \` \(or \`rg -l --null\`\) combined with \`xargs -0\` or \`while IFS= read -r -d '' file\`. The \`-0\`/\`--null\` flag outputs null bytes \(ASCII 0\) between filenames instead of newlines. Parsers like \`xargs -0\`, \`perl -0\`, or \`read -d ''\` treat null as the delimiter, safely handling filenames containing any character except null \(which is impossible in Unix filenames\).
Journey Context:
Standard Unix pipelines split on the IFS \(Internal Field Separator, usually space/tab/newline\), causing catastrophic failures when filenames contain these characters. The naive \`rg ... \| xargs rm\` will try to delete separate files if a match is in 'My Document.txt', attempting to delete 'My' and 'Document.txt'. Workarounds like \`xargs -d '\\n'\` still fail on filenames with newlines \(allowed in Unix\). The null-delimited protocol \(introduced by \`find -print0\` and adopted by ripgrep\) uses the only character that cannot appear in a path as the delimiter. This creates a robust, injection-safe pipeline for batch processing. This is essential for security when processing untrusted filenames \(e.g., user uploads\) and for reliability in large codebases where filenames may contain spaces or international characters.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T21:27:52.975115+00:00— report_created — created