From e27b24005d75228a2ec94f47065930aad86c8ec9 Mon Sep 17 00:00:00 2001 From: Looly Date: Mon, 20 Jun 2022 12:25:23 +0800 Subject: [PATCH] =?UTF-8?q?LocalDateTimeUtil.parse=E6=94=B9=E4=B8=BAblank?= =?UTF-8?q?=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../main/java/cn/hutool/core/date/LocalDateTimeUtil.java | 4 ++-- .../java/cn/hutool/core/date/LocalDateTimeUtilTest.java | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7a6cc686..48633aaa1 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * 【core 】 修改ObjectUtil.isNull逻辑(issue#I5COJF@Gitee) * 【core 】 BlockPolicy增加线程池关闭后的逻辑(pr#660@Gitee) * 【core 】 Ipv4Util增加ipv4ToLong重载(pr#661@Gitee) +* 【core 】 LocalDateTimeUtil.parse改为blank检查(issue#I5CZJ9@Gitee) * ### 🐞Bug修复 * 【extra 】 修复createExtractor中抛出异常后流未关闭问题(pr#2384@Github) diff --git a/hutool-core/src/main/java/cn/hutool/core/date/LocalDateTimeUtil.java b/hutool-core/src/main/java/cn/hutool/core/date/LocalDateTimeUtil.java index 708880749..0eb2a0bc5 100755 --- a/hutool-core/src/main/java/cn/hutool/core/date/LocalDateTimeUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/date/LocalDateTimeUtil.java @@ -229,7 +229,7 @@ public class LocalDateTimeUtil { * @return {@link LocalDateTime} */ public static LocalDateTime parse(CharSequence text, DateTimeFormatter formatter) { - if (null == text) { + if (StrUtil.isBlank(text)) { return null; } if (null == formatter) { @@ -247,7 +247,7 @@ public class LocalDateTimeUtil { * @return {@link LocalDateTime} */ public static LocalDateTime parse(CharSequence text, String format) { - if (null == text) { + if (StrUtil.isBlank(text)) { return null; } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/LocalDateTimeUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/date/LocalDateTimeUtilTest.java index 08a89b122..f99b49e81 100755 --- a/hutool-core/src/test/java/cn/hutool/core/date/LocalDateTimeUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/LocalDateTimeUtilTest.java @@ -11,7 +11,6 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalAccessor; -import java.util.Date; public class LocalDateTimeUtilTest { @@ -237,4 +236,10 @@ public class LocalDateTimeUtilTest { final LocalDateTime of = LocalDateTimeUtil.of((TemporalAccessor) instant); Console.log(of); } + + @Test + public void parseBlankTest(){ + final LocalDateTime parse = LocalDateTimeUtil.parse(""); + Assert.assertNull(parse); + } }