mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-09 14:38:59 +02:00
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:
co-authored by
Claude Fable 5
parent
a97aff9d0b
commit
6b9f10a8b7
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user