fix isBase64

This commit is contained in:
Looly 2021-10-09 20:24:02 +08:00
parent 74c6dca648
commit 0f96a95f2c
2 changed files with 12 additions and 11 deletions

View File

@ -22,6 +22,7 @@
* 【core 】 Week增加of重载支持DayOfWekpr#1872@Github
* 【poi 】 优化read避免多次创建CopyOptionsissue#1875@Github
* 【core 】 优化CsvReader实现可控遍历pr#1873@Github
* 【core 】 优化Base64.isBase64判断pr#1879@Github
### 🐞Bug修复
* 【http 】 修复HttpCookie设置cookies的方法不符合RFC6265规范问题pr#418@Gitee

View File

@ -322,12 +322,12 @@ public class Base64 {
* @return 是否为Base64
* @since 5.7.5
*/
public static boolean isBase64(CharSequence base64){
public static boolean isBase64(CharSequence base64) {
if (base64 == null || base64.length() < 2) {
return false;
}
byte[] bytes = StrUtil.utf8Bytes(base64);
final byte[] bytes = StrUtil.utf8Bytes(base64);
if (bytes.length != base64.length()) {
// 如果长度不相等说明存在双字节字符肯定不是Base64直接返回false
@ -344,15 +344,15 @@ public class Base64 {
* @return 是否为Base64
* @since 5.7.5
*/
public static boolean isBase64(byte[] base64Bytes){
public static boolean isBase64(byte[] base64Bytes) {
boolean hasPadding = false;
for (byte base64Byte : base64Bytes) {
if(hasPadding){
if('=' != base64Byte){
if (hasPadding) {
if ('=' != base64Byte) {
// 前一个字符是'='则后边的字符都必须是'=''='只能都位于结尾
return false;
}
} else if('=' == base64Byte){
} else if ('=' == base64Byte) {
// 发现'=' 标记之
hasPadding = true;
} else if (false == (Base64Decoder.isBase64Code(base64Byte) || isWhiteSpace(base64Byte))) {
@ -364,12 +364,12 @@ public class Base64 {
private static boolean isWhiteSpace(byte byteToCheck) {
switch (byteToCheck) {
case ' ' :
case '\n' :
case '\r' :
case '\t' :
case ' ':
case '\n':
case '\r':
case '\t':
return true;
default :
default:
return false;
}
}