From ee07df3c7b7f6cf243b583393a0df14f3452b195 Mon Sep 17 00:00:00 2001 From: deary Date: Sun, 23 Nov 2025 21:38:17 +0800 Subject: [PATCH] =?UTF-8?q?refactor(helper):=20=E4=BC=98=E5=8C=96=E5=9B=BE?= =?UTF-8?q?=E7=89=87URL=E6=A3=80=E6=9F=A5=E9=80=BB=E8=BE=91=E5=B9=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A9=BA=E5=80=BC=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用更清晰的startsWith方法替代substring进行URL检查 - 增加对空值和非法类型的处理 - 简化http到https的转换逻辑 --- sheep/helper/tools.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sheep/helper/tools.js b/sheep/helper/tools.js index 49efcecb..8712917e 100644 --- a/sheep/helper/tools.js +++ b/sheep/helper/tools.js @@ -19,15 +19,19 @@ export default { * @param {String} url -图片地址 */ checkMPUrl(url) { + if (!url || typeof url !== 'string') { + return url; + } + // #ifdef MP if ( - url.substring(0, 4) === 'http' && - url.substring(0, 5) !== 'https' && - url.substring(0, 12) !== 'http://store' && - url.substring(0, 10) !== 'http://tmp' && - url.substring(0, 10) !== 'http://usr' + url.startsWith('http://') && + !url.startsWith('https://') && + !url.startsWith('http://store') && + !url.startsWith('http://tmp') && + !url.startsWith('http://usr') ) { - url = 'https' + url.substring(4, url.length); + url = url.replace('http://', 'https://'); } // #endif return url;