fix(DIS-102): handle both slash styles for Windows path sanitization
os.homedir() returns backslashes on Windows but Claude Code outputs paths with forward slashes. Replace both C:\Users\x and C:/Users/x variants so home and repoRoot are always redacted. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
90f96bdbf4
commit
5869c15f9d
1 changed files with 18 additions and 3 deletions
|
|
@ -13,6 +13,17 @@ export interface SanitizeOptions {
|
||||||
* 3. Discord bot token pattern → <redacted>
|
* 3. Discord bot token pattern → <redacted>
|
||||||
* 4. Anthropic API key pattern → <redacted>
|
* 4. Anthropic API key pattern → <redacted>
|
||||||
*/
|
*/
|
||||||
|
/** Returns both backslash and forward-slash variants of a path (for Windows). */
|
||||||
|
function pathVariants(p: string): string[] {
|
||||||
|
const fwd = p.replace(/\\/g, "/");
|
||||||
|
const bwd = p.replace(/\//g, "\\");
|
||||||
|
return fwd === bwd ? [p] : [p, fwd, bwd];
|
||||||
|
}
|
||||||
|
|
||||||
|
function replaceAll(text: string, search: string, replacement: string): string {
|
||||||
|
return text.split(search).join(replacement);
|
||||||
|
}
|
||||||
|
|
||||||
export function sanitizeForDiscord(
|
export function sanitizeForDiscord(
|
||||||
text: string,
|
text: string,
|
||||||
opts: SanitizeOptions = {}
|
opts: SanitizeOptions = {}
|
||||||
|
|
@ -22,12 +33,16 @@ export function sanitizeForDiscord(
|
||||||
// 1. Replace repo root before home so that sub-paths are caught by the
|
// 1. Replace repo root before home so that sub-paths are caught by the
|
||||||
// more specific substitution first (repoRoot is usually inside home).
|
// more specific substitution first (repoRoot is usually inside home).
|
||||||
if (opts.repoRoot) {
|
if (opts.repoRoot) {
|
||||||
result = result.split(opts.repoRoot).join("<disclaw>");
|
for (const variant of pathVariants(opts.repoRoot)) {
|
||||||
|
result = replaceAll(result, variant, "<disclaw>");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Replace home directory with ~
|
// 2. Replace home directory with ~ (both slash styles for Windows)
|
||||||
if (opts.home) {
|
if (opts.home) {
|
||||||
result = result.split(opts.home).join("~");
|
for (const variant of pathVariants(opts.home)) {
|
||||||
|
result = replaceAll(result, variant, "~");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Discord bot token — format: [MN]<23 base64url>.<6 base64url>.<27 base64url>
|
// 3. Discord bot token — format: [MN]<23 base64url>.<6 base64url>.<27 base64url>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue