fix(all): 修复了一些bug

This commit is contained in:
2026-02-24 17:11:25 +08:00
parent 75b4341330
commit c2f041b03b
14 changed files with 816 additions and 191 deletions

View File

@@ -9,11 +9,27 @@ interface IpInputProps {
}
const IP_REGEX = /^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)$/
const DOMAIN_REGEX = /^(?!:\/\/)([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/
const DOMAIN_REGEX = /^([a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/
function normalizeTarget(value: string): string {
let target = value.trim().toLowerCase()
// Remove protocol prefix if present
target = target.replace(/^https?:\/\//, '')
// Strip userinfo if a full URL with credentials was pasted
const atIndex = target.lastIndexOf('@')
if (atIndex !== -1) {
target = target.slice(atIndex + 1)
}
// Remove path, query, and fragment
target = target.split(/[/?#]/)[0]
// Remove port if present
target = target.split(':')[0]
return target
}
function isValidTarget(value: string): boolean {
const trimmed = value.trim().toLowerCase()
return IP_REGEX.test(trimmed) || DOMAIN_REGEX.test(trimmed)
const normalized = normalizeTarget(value)
return IP_REGEX.test(normalized) || DOMAIN_REGEX.test(normalized)
}
export default function IpInput({ onTest, testing }: IpInputProps) {
@@ -31,13 +47,14 @@ export default function IpInput({ onTest, testing }: IpInputProps) {
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault()
const trimmed = target.trim()
if (!isValidTarget(trimmed)) {
if (!isValidTarget(target)) {
setError(t('无效的IP地址或域名', 'Invalid IP address or domain'))
return
}
const normalized = normalizeTarget(target)
setTarget(normalized) // Update display to show normalized value
setError('')
onTest(trimmed)
onTest(normalized)
}
return (