~cytrogen/gstack

ref: dc0bae82d31bda5f9a5f714a6d43946600c55827 gstack/browse/src/sidebar-utils.ts -rw-r--r-- 629 bytes
dc0bae82 — Garry Tan fix: sidebar agent uses real tab URL instead of stale Playwright URL (v0.12.6.0) (#544) 13 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;
  }
}