Merge pull request #876 from AndrewBastin/bugfix/873
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
function generateIPRE(protocol) {
|
const wsRegex = generateREForProtocol("^(wss?:\\/\\/)?")
|
||||||
|
const sseRegex = generateREForProtocol("^(https?:\\/\\/)?")
|
||||||
|
const socketioRegex = generateREForProtocol("^((wss?:\\/\\/)|(https?:\\/\\/))?")
|
||||||
|
|
||||||
|
function generateREForProtocol(protocol) {
|
||||||
return new RegExp(
|
return new RegExp(
|
||||||
`${protocol}(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$`
|
`${protocol}[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&\\/\\/=]*)`
|
||||||
)
|
|
||||||
}
|
|
||||||
function generateHostnameRE(protocol) {
|
|
||||||
return new RegExp(
|
|
||||||
`${protocol}(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]).)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9/])$`
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -13,28 +12,19 @@ function generateHostnameRE(protocol) {
|
|||||||
* valid url for ws/wss
|
* valid url for ws/wss
|
||||||
*/
|
*/
|
||||||
export function wsValid(url) {
|
export function wsValid(url) {
|
||||||
const protocol = "^(wss?:\\/\\/)?"
|
return wsRegex.test(url)
|
||||||
const validIP = generateIPRE(protocol)
|
|
||||||
const validHostname = generateHostnameRE(protocol)
|
|
||||||
return validIP.test(url) || validHostname.test(url)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* valid url for http/https
|
* valid url for http/https
|
||||||
*/
|
*/
|
||||||
export function sseValid(url) {
|
export function sseValid(url) {
|
||||||
const protocol = "^(https?:\\/\\/)?"
|
return sseRegex.test(url)
|
||||||
const validIP = generateIPRE(protocol)
|
|
||||||
const validHostname = generateHostnameRE(protocol)
|
|
||||||
return validIP.test(url) || validHostname.test(url)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* valid url for ws/wss/http/https
|
* valid url for ws/wss/http/https
|
||||||
*/
|
*/
|
||||||
export function socketioValid(url) {
|
export function socketioValid(url) {
|
||||||
const protocol = "^((wss?:\\/\\/)|(https?:\\/\\/))?"
|
return socketioRegex.test(url)
|
||||||
const validIP = generateIPRE(protocol)
|
|
||||||
const validHostname = generateHostnameRE(protocol)
|
|
||||||
return validIP.test(url) || validHostname.test(url)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user