From 6b9f10a8b70a9beed267e90d3f2cd303f95512fc Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Mon, 31 Aug 2026 20:56:22 +0000 Subject: [PATCH] refactor(redact): name the SSH-remote path lookahead constant Wave polish on the #2734 absorption: the 512-char scp-path lookahead window follows the UUID_CONTEXT_CHARS named-constant convention instead of a magic number at the slice site. Co-Authored-By: Claude Fable 5 --- lib/redact-engine.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/redact-engine.ts b/lib/redact-engine.ts index de1738e3e..04a1ea45b 100644 --- a/lib/redact-engine.ts +++ b/lib/redact-engine.ts @@ -267,6 +267,10 @@ function hasNear( * - `git@` for the major forges, whose bare form appears in docs * and in `ssh -T git@github.com` connectivity checks with no path at all. */ +/** Lookahead window for the scp-path suffix check — long enough for any real + * remote path, bounded so a pathological unbroken line can't grow the scan. */ +const SSH_REMOTE_PATH_LOOKAHEAD_CHARS = 512; + function isSshGitRemote(email: string, text: string, spanStart: number): boolean { const at = email.lastIndexOf("@"); if (at < 0) return false; @@ -278,7 +282,10 @@ function isSshGitRemote(email: string, text: string, spanStart: number): boolean // Any host in `@:.git` position. The path stops at // whitespace or a quote so a trailing delimiter never defeats the suffix. - const rest = text.slice(spanStart + email.length, spanStart + email.length + 512); + const rest = text.slice( + spanStart + email.length, + spanStart + email.length + SSH_REMOTE_PATH_LOOKAHEAD_CHARS, + ); const scp = /^:(?!\/)([^\s'"`<>]*)/.exec(rest); if (scp && /\.git\/?$/.test(scp[1])) return true;