(input)
| 400 | } |
| 401 | |
| 402 | function validateAndExtractHost(input) { |
| 403 | try { |
| 404 | const url = new URL(input); |
| 405 | if (url.protocol !== "http:" && url.protocol !== "https:") throw new Error(); |
| 406 | return url.hostname; |
| 407 | } catch { |
| 408 | const hostnameRegex = /^(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\.[A-Za-z]{2,})+$/; |
| 409 | return hostnameRegex.test(input) ? input : null; |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | $('addHostname').addEventListener('click', () => { |
| 414 | const input = $('newWebsite'); |
no outgoing calls
no test coverage detected