fix: allow image URLs without file extensions
This commit is contained in:
parent
b9a1255909
commit
1cb1c1c179
@ -766,10 +766,17 @@ const isValidImageUrl = (url: string): boolean => {
|
||||
if (!url || typeof url !== 'string') return false
|
||||
try {
|
||||
const urlObj = new URL(url)
|
||||
if (!['http:', 'https:'].includes(urlObj.protocol)) {
|
||||
return false
|
||||
}
|
||||
|
||||
const pathname = urlObj.pathname.toLowerCase()
|
||||
const imageExtensions = ['.jpg', '.jpeg', '.png', '.webp', '.gif', '.bmp']
|
||||
return imageExtensions.some(ext => pathname.endsWith(ext)) ||
|
||||
urlObj.pathname.match(/\.(jpg|jpeg|png|webp|gif|bmp)(\?|$)/i) !== null
|
||||
|
||||
const hasImageExtension = imageExtensions.some(ext => pathname.endsWith(ext)) ||
|
||||
urlObj.pathname.match(/\.(jpg|jpeg|png|webp|gif|bmp)(\?|$)/i) !== null
|
||||
|
||||
return hasImageExtension || pathname.length > 0
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -308,10 +308,17 @@ const isValidImageUrl = (url: string): boolean => {
|
||||
if (!url || typeof url !== 'string') return false
|
||||
try {
|
||||
const urlObj = new URL(url)
|
||||
if (!['http:', 'https:'].includes(urlObj.protocol)) {
|
||||
return false
|
||||
}
|
||||
|
||||
const pathname = urlObj.pathname.toLowerCase()
|
||||
const imageExtensions = ['.jpg', '.jpeg', '.png', '.webp', '.gif', '.bmp']
|
||||
return imageExtensions.some(ext => pathname.endsWith(ext)) ||
|
||||
urlObj.pathname.match(/\.(jpg|jpeg|png|webp|gif|bmp)(\?|$)/i) !== null
|
||||
|
||||
const hasImageExtension = imageExtensions.some(ext => pathname.endsWith(ext)) ||
|
||||
urlObj.pathname.match(/\.(jpg|jpeg|png|webp|gif|bmp)(\?|$)/i) !== null
|
||||
|
||||
return hasImageExtension || pathname.length > 0
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user