mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix isBase64
This commit is contained in:
parent
74c6dca648
commit
0f96a95f2c
@ -22,6 +22,7 @@
|
||||
* 【core 】 Week增加of重载,支持DayOfWek(pr#1872@Github)
|
||||
* 【poi 】 优化read,避免多次创建CopyOptions(issue#1875@Github)
|
||||
* 【core 】 优化CsvReader,实现可控遍历(pr#1873@Github)
|
||||
* 【core 】 优化Base64.isBase64判断(pr#1879@Github)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【http 】 修复HttpCookie设置cookies的方法,不符合RFC6265规范问题(pr#418@Gitee)
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user