MCPcopy
hub / github.com/simstudioai/sim / sanitizeUrlForLog

Function sanitizeUrlForLog

apps/sim/lib/core/utils/logging.ts:6–21  ·  view source on GitHub ↗
(url: string, maxLength = 120)

Source from the content-addressed store, hash-verified

4 * Sanitize URLs for logging by stripping query/hash and truncating.
5 */
6export function sanitizeUrlForLog(url: string, maxLength = 120): string {
7 if (!url) return ''
8
9 const trimmed = url.trim()
10 try {
11 const hasProtocol = /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(trimmed)
12 const parsed = new URL(trimmed, hasProtocol ? undefined : 'http://localhost')
13 const origin = parsed.origin === 'null' ? '' : parsed.origin
14 const sanitized = `${origin}${parsed.pathname}`
15 const result = sanitized || parsed.pathname || trimmed
16 return truncate(result, maxLength)
17 } catch {
18 const withoutQuery = trimmed.split('?')[0].split('#')[0]
19 return truncate(withoutQuery, maxLength)
20 }
21}

Callers 3

fetchWithDNSPinningFunction · 0.90
secureFetchFunction · 0.90
handleExternalUrlFunction · 0.90

Calls 2

truncateFunction · 0.90
testMethod · 0.80

Tested by

no test coverage detected