(input: string)
| 5 | * not a registrable domain (e.g. `example.com`), which callers treat as invalid. |
| 6 | */ |
| 7 | export function normalizeSSODomain(input: string): string | null { |
| 8 | if (typeof input !== 'string') return null |
| 9 | |
| 10 | let value = input.trim().toLowerCase() |
| 11 | if (!value) return null |
| 12 | |
| 13 | value = value.replace(/^[a-z][a-z0-9+.-]*:\/\//, '') |
| 14 | value = value.replace(/^\*\./, '').replace(/^@/, '') |
| 15 | value = value.split('/')[0] |
| 16 | value = value.split('?')[0] |
| 17 | value = value.split('@').pop() ?? value |
| 18 | value = value.split(':')[0] |
| 19 | value = value.replace(/\.$/, '') |
| 20 | |
| 21 | if (!/^[a-z0-9-]+(\.[a-z0-9-]+)+$/.test(value)) return null |
| 22 | |
| 23 | const labels = value.split('.') |
| 24 | if (labels.some((label) => label.length === 0 || label.length > 63)) return null |
| 25 | if (/^\d+$/.test(labels[labels.length - 1])) return null |
| 26 | |
| 27 | return value |
| 28 | } |
no test coverage detected