mirror of https://github.com/langgenius/dify.git
chore: improve mcp server url validation (#27558)
This commit is contained in:
parent
3395297c3e
commit
0caeaf6e5c
|
|
@ -141,8 +141,8 @@ const MCPModal = ({
|
|||
|
||||
const isValidUrl = (string: string) => {
|
||||
try {
|
||||
const urlPattern = /^(https?:\/\/)((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|((\d{1,3}\.){3}\d{1,3})|localhost)(:\d+)?(\/[-a-z\d%_.~+]*)*(\?[;&a-z\d%_.~+=-]*)?/i
|
||||
return urlPattern.test(string)
|
||||
const url = new URL(string)
|
||||
return url.protocol === 'http:' || url.protocol === 'https:'
|
||||
}
|
||||
catch {
|
||||
return false
|
||||
|
|
|
|||
Loading…
Reference in New Issue