Skip to content

Commit 308400a

Browse files
committed
fix:检测是否是合法URL Path 支持http图片链接地址
1 parent b006dc9 commit 308400a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/plugin/admin/app/common/Util.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,23 @@ public static function filterNum($var)
161161
}
162162

163163
/**
164-
* 检测是否是合法URL Path
164+
* @desc 检测是否是合法URL Path
165165
* @param $var
166166
* @return string
167167
* @throws BusinessException
168168
*/
169169
public static function filterUrlPath($var): string
170170
{
171-
if (!is_string($var) || !preg_match('/^[a-zA-Z0-9_\-\/&?.]+$/', $var)) {
172-
throw new BusinessException('参数不合法');
171+
if (!is_string($var)) {
172+
throw new BusinessException('参数不合法,地址必须是一个字符串!');
173+
}
174+
175+
if (strpos($var, 'https://') === 0 || strpos($var, 'http://') === 0) {
176+
if (!filter_var($var, FILTER_VALIDATE_URL)) {
177+
throw new BusinessException('参数不合法,不是合法的URL地址!');
178+
}
179+
} elseif (!preg_match('/^[a-zA-Z0-9_\-\/&?.]+$/', $var)) {
180+
throw new BusinessException('参数不合法,不是合法的Path!');
173181
}
174182
return $var;
175183
}

0 commit comments

Comments
 (0)