From 8bb47018e629385928e1806fa90aa963d80a7e95 Mon Sep 17 00:00:00 2001 From: Looly Date: Tue, 23 Jun 2020 18:02:38 +0800 Subject: [PATCH] fix brief bug --- CHANGELOG.md | 3 ++- .../src/main/java/cn/hutool/core/util/StrUtil.java | 4 ++-- .../src/test/java/cn/hutool/core/util/StrUtilTest.java | 9 ++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f093f7f7..63a66d7d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ------------------------------------------------------------------------------------------------------------- -## 5.3.9 (2020-06-17) +## 5.3.9 (2020-06-23) ### 新特性 * 【core 】 DateUtil增加formatChineseDate(pr#932@Github) @@ -11,6 +11,7 @@ ### Bug修复 * 【core 】 修复NumberUtil.partValue有余数问题(issue#I1KX66@Gitee) * 【core 】 修复BeanUtil.isEmpty不能忽略static字段问题(issue#I1KZI6@Gitee) +* 【core 】 修复StrUtil.brief长度问题(pr#930@Github) ------------------------------------------------------------------------------------------------------------- ## 5.3.8 (2020-06-16) diff --git a/hutool-core/src/main/java/cn/hutool/core/util/StrUtil.java b/hutool-core/src/main/java/cn/hutool/core/util/StrUtil.java index 118abc4d9..8d15e677c 100644 --- a/hutool-core/src/main/java/cn/hutool/core/util/StrUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/util/StrUtil.java @@ -3312,11 +3312,11 @@ public class StrUtil { if (null == str) { return null; } - if ((str.length() + 3) <= maxLength) { + if (str.length() <= maxLength) { return str.toString(); } int w = maxLength / 2; - int l = str.length(); + int l = str.length() + 3; final String str2 = str.toString(); return format("{}...{}", str2.substring(0, maxLength - w), str2.substring(l - w)); diff --git a/hutool-core/src/test/java/cn/hutool/core/util/StrUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/StrUtilTest.java index f18c345c0..7c979d620 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/StrUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/StrUtilTest.java @@ -448,5 +448,12 @@ public class StrUtilTest { String[] results2 = StrUtil.subBetweenAll(src2,"/*","*/"); Assert.assertEquals(0, results2.length); } - + + @Test + public void briefTest(){ + String str = RandomUtil.randomString(1000); + int maxLength = RandomUtil.randomInt(1000); + String brief = StrUtil.brief(str, maxLength); + Assert.assertEquals(brief.length(), maxLength); + } }