/** * URL ที่นำทางด้วย script ได้อย่างปลอดภัย (`location.assign/replace`, `window.open`) * — ช่องทางเหล่านี้ไม่มีตัวกัน `javascript:` แบบ `` ของ React หรือ router ของ Next * รับเฉพาะ http(s) และ path ภายใน (relative); คืน URL ที่ resolve แล้ว หรือ null ถ้าไม่ปลอดภัย * ไม่ได้กัน open redirect ไปโดเมนอื่น — ถ้าค่ามาจาก URL/ผู้ใช้ แอปต้องเช็กปลายทางเอง */ export function safeNavigableUrl(href: string | null | undefined): string | null { if (!href || typeof window === "undefined") return null; try { const url = new URL(href, window.location.href); return url.protocol === "http:" || url.protocol === "https:" ? url.href : null; } catch { return null; } }