mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix brief bug
This commit is contained in:
@@ -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));
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user