chore: improve mcp server url validation (#27558)

This commit is contained in:
Novice
2025-10-28 17:30:01 +08:00
committed by GitHub
parent 3395297c3e
commit 0caeaf6e5c

View File

@@ -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