mirror of
https://gitee.com/dromara/hutool.git
synced 2025-07-15 14:04:33 +08:00
fix bugs
This commit is contained in:
parent
2244f63adc
commit
b5297bd7e6
@ -15,6 +15,8 @@
|
|||||||
### Bug修复
|
### Bug修复
|
||||||
* 【db】 修复MetaUtil.getTableMeta()方法未释放ResultSet的bug(issue#I148GH@Gitee)
|
* 【db】 修复MetaUtil.getTableMeta()方法未释放ResultSet的bug(issue#I148GH@Gitee)
|
||||||
* 【core】 修复DateUtil.age闰年导致的问题(issue#I14BVN@Gitee)
|
* 【core】 修复DateUtil.age闰年导致的问题(issue#I14BVN@Gitee)
|
||||||
|
* 【extra】 修复ServletUtil.getCookie大小写问题(pr#79@Gitee)
|
||||||
|
* 【core】 修复IdcardUtil.isValidCard18报错问题(issue#I14LTJ@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public class CaseInsensitiveMap<K, V> extends CustomKeyMap<K, V> {
|
|||||||
* @param loadFactor 加载因子
|
* @param loadFactor 加载因子
|
||||||
*/
|
*/
|
||||||
public CaseInsensitiveMap(int initialCapacity, float loadFactor) {
|
public CaseInsensitiveMap(int initialCapacity, float loadFactor) {
|
||||||
super(new HashMap<K, V>(initialCapacity, loadFactor));
|
super(new HashMap<>(initialCapacity, loadFactor));
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------- Constructor end
|
//------------------------------------------------------------------------- Constructor end
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ public class CaseInsensitiveMap<K, V> extends CustomKeyMap<K, V> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Object customKey(Object key) {
|
protected Object customKey(Object key) {
|
||||||
if (null != key && key instanceof CharSequence) {
|
if (key instanceof CharSequence) {
|
||||||
key = key.toString().toLowerCase();
|
key = key.toString().toLowerCase();
|
||||||
}
|
}
|
||||||
return key;
|
return key;
|
||||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.date.DatePattern;
|
|||||||
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.hutool.core.lang.PatternPool;
|
||||||
import cn.hutool.core.lang.Validator;
|
import cn.hutool.core.lang.Validator;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -137,7 +138,7 @@ public class IdcardUtil {
|
|||||||
if (idCard.length() != CHINA_ID_MIN_LENGTH) {
|
if (idCard.length() != CHINA_ID_MIN_LENGTH) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (Validator.isNumber(idCard)) {
|
if (ReUtil.isMatch(PatternPool.NUMBERS, idCard)) {
|
||||||
// 获取出生年月日
|
// 获取出生年月日
|
||||||
String birthday = idCard.substring(6, 12);
|
String birthday = idCard.substring(6, 12);
|
||||||
Date birthDate = DateUtil.parse(birthday, "yyMMdd");
|
Date birthDate = DateUtil.parse(birthday, "yyMMdd");
|
||||||
@ -168,9 +169,9 @@ public class IdcardUtil {
|
|||||||
int length = idCard.length();
|
int length = idCard.length();
|
||||||
switch (length) {
|
switch (length) {
|
||||||
case 18:// 18位身份证
|
case 18:// 18位身份证
|
||||||
return isvalidCard18(idCard);
|
return isValidCard18(idCard);
|
||||||
case 15:// 15位身份证
|
case 15:// 15位身份证
|
||||||
return isvalidCard15(idCard);
|
return isValidCard15(idCard);
|
||||||
case 10: {// 10位身份证,港澳台地区
|
case 10: {// 10位身份证,港澳台地区
|
||||||
String[] cardval = isValidCard10(idCard);
|
String[] cardval = isValidCard10(idCard);
|
||||||
return null != cardval && cardval[2].equals("true");
|
return null != cardval && cardval[2].equals("true");
|
||||||
@ -211,7 +212,7 @@ public class IdcardUtil {
|
|||||||
* @param idCard 待验证的身份证
|
* @param idCard 待验证的身份证
|
||||||
* @return 是否有效的18位身份证
|
* @return 是否有效的18位身份证
|
||||||
*/
|
*/
|
||||||
public static boolean isvalidCard18(String idCard) {
|
public static boolean isValidCard18(String idCard) {
|
||||||
if (CHINA_ID_MAX_LENGTH != idCard.length()) {
|
if (CHINA_ID_MAX_LENGTH != idCard.length()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -225,7 +226,7 @@ public class IdcardUtil {
|
|||||||
String code17 = idCard.substring(0, 17);
|
String code17 = idCard.substring(0, 17);
|
||||||
// 第18位
|
// 第18位
|
||||||
char code18 = Character.toLowerCase(idCard.charAt(17));
|
char code18 = Character.toLowerCase(idCard.charAt(17));
|
||||||
if (Validator.isNumber(code17)) {
|
if (ReUtil.isMatch(PatternPool.NUMBERS, code17)) {
|
||||||
// 获取校验位
|
// 获取校验位
|
||||||
char val = getCheckCode18(code17);
|
char val = getCheckCode18(code17);
|
||||||
return val == code18;
|
return val == code18;
|
||||||
@ -239,11 +240,11 @@ public class IdcardUtil {
|
|||||||
* @param idCard 身份编码
|
* @param idCard 身份编码
|
||||||
* @return 是否合法
|
* @return 是否合法
|
||||||
*/
|
*/
|
||||||
public static boolean isvalidCard15(String idCard) {
|
public static boolean isValidCard15(String idCard) {
|
||||||
if (CHINA_ID_MIN_LENGTH != idCard.length()) {
|
if (CHINA_ID_MIN_LENGTH != idCard.length()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (Validator.isNumber(idCard)) {
|
if (ReUtil.isMatch(PatternPool.NUMBERS, idCard)) {
|
||||||
// 省份
|
// 省份
|
||||||
String proCode = idCard.substring(0, 2);
|
String proCode = idCard.substring(0, 2);
|
||||||
if (null == cityCodes.get(proCode)) {
|
if (null == cityCodes.get(proCode)) {
|
||||||
|
@ -12,6 +12,7 @@ import org.junit.Test;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class IdcardUtilTest {
|
public class IdcardUtilTest {
|
||||||
|
|
||||||
private static final String ID_18 = "321083197812162119";
|
private static final String ID_18 = "321083197812162119";
|
||||||
private static final String ID_15 = "150102880730303";
|
private static final String ID_15 = "150102880730303";
|
||||||
|
|
||||||
@ -71,4 +72,10 @@ public class IdcardUtilTest {
|
|||||||
Assert.assertEquals(1, gender);
|
Assert.assertEquals(1, gender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isValidCard18Test(){
|
||||||
|
final boolean isValidCard18 = IdcardUtil.isValidCard18("3301022011022000D6");
|
||||||
|
Assert.assertFalse(isValidCard18);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import cn.hutool.core.exceptions.UtilException;
|
|||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.io.IORuntimeException;
|
import cn.hutool.core.io.IORuntimeException;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.hutool.core.map.CaseInsensitiveMap;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
@ -410,13 +411,12 @@ public class ServletUtil {
|
|||||||
* @return Cookie map
|
* @return Cookie map
|
||||||
*/
|
*/
|
||||||
public static Map<String, Cookie> readCookieMap(HttpServletRequest httpServletRequest) {
|
public static Map<String, Cookie> readCookieMap(HttpServletRequest httpServletRequest) {
|
||||||
Map<String, Cookie> cookieMap = new HashMap<>();
|
final Map<String, Cookie> cookieMap = new CaseInsensitiveMap<>();
|
||||||
Cookie[] cookies = httpServletRequest.getCookies();
|
final Cookie[] cookies = httpServletRequest.getCookies();
|
||||||
if (null == cookies) {
|
if (null != cookies) {
|
||||||
return null;
|
for (Cookie cookie : cookies) {
|
||||||
}
|
cookieMap.put(cookie.getName(), cookie);
|
||||||
for (Cookie cookie : cookies) {
|
}
|
||||||
cookieMap.put(cookie.getName(), cookie);
|
|
||||||
}
|
}
|
||||||
return cookieMap;
|
return cookieMap;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user