~cytrogen/gstack

ref: cdd6f7865d0edf741f658a256115cbf77dace61b gstack/browse/src/sidebar-utils.ts -rw-r--r-- 629 bytes
cdd6f786 — Garry Tan feat: community wave — 7 fixes, relink, sidebar Write, discoverability (v0.13.5.0) (#641) 10 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
 * Shared sidebar utilities — extracted for testability.
 */

/**
 * Sanitize a URL from the Chrome extension before embedding in a prompt.
 * Only accepts http/https, strips control characters, truncates to 2048 chars.
 * Returns null if the URL is invalid or uses a non-http scheme.
 */
export function sanitizeExtensionUrl(url: string | null | undefined): string | null {
  if (!url) return null;
  try {
    const u = new URL(url);
    if (u.protocol === 'http:' || u.protocol === 'https:') {
      return u.href.replace(/[\x00-\x1f\x7f]/g, '').slice(0, 2048);
    }
    return null;
  } catch {
    return null;
  }
}