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 <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-08-31 20:56:22 +00:00
co-authored by Claude Fable 5
parent a97aff9d0b
commit 6b9f10a8b7
+8 -1
View File
@@ -267,6 +267,10 @@ function hasNear(
* - `git@<known-host>` 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 `<user>@<host>:<path>.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;