15 lines
468 B
JavaScript
15 lines
468 B
JavaScript
|
|
/**
|
|||
|
|
* 小程序 <image src> 合法判断:避免 undefined 字符串、相对脏值触发「illegal src」
|
|||
|
|
*/
|
|||
|
|
function isSafeImageSrc(u) {
|
|||
|
|
if (u == null) return false
|
|||
|
|
const s = String(u).trim()
|
|||
|
|
if (!s || s === 'undefined' || s === 'null') return false
|
|||
|
|
if (/^https?:\/\//i.test(s)) return true
|
|||
|
|
if (s.startsWith('wxfile://') || s.startsWith('cloud://')) return true
|
|||
|
|
if (s.startsWith('/')) return true
|
|||
|
|
return false
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
module.exports = { isSafeImageSrc }
|