Merge pull request #1879 from wangliang181230/optimize-base64-2

Base64.isBase64(base64)方法,如果存在双字节字符,直接返回false。
This commit is contained in:
Golden Looly 2021-10-09 20:19:18 +08:00 committed by GitHub
commit 74c6dca648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -323,7 +323,18 @@ public class Base64 {
* @since 5.7.5 * @since 5.7.5
*/ */
public static boolean isBase64(CharSequence base64){ public static boolean isBase64(CharSequence base64){
return isBase64(StrUtil.utf8Bytes(base64)); if (base64 == null || base64.length() < 2) {
return false;
}
byte[] bytes = StrUtil.utf8Bytes(base64);
if (bytes.length != base64.length()) {
// 如果长度不相等说明存在双字节字符肯定不是Base64直接返回false
return false;
}
return isBase64(bytes);
} }
/** /**