export function normalizeInternalRedirectPath(value: unknown, fallback = '/') { const raw = String(value ?? '').trim() if (!raw) return fallback if (!raw.startsWith('/') || raw.startsWith('//')) { return fallback } try { const parsed = new URL(raw, 'https://internal.local') return `${parsed.pathname}${parsed.search}${parsed.hash}` } catch { return fallback } } export function buildDingtalkAutoLoginPath(redirectPath: unknown) { const target = normalizeInternalRedirectPath(redirectPath) return `/login?dingtalk_redirect=true&redirect=${encodeURIComponent(target)}` } export function buildDingtalkEntryPath(redirectPath: unknown) { const target = normalizeInternalRedirectPath(redirectPath) return `/dingtalk-entry?redirect=${encodeURIComponent(target)}` }