修复DataSize.parse(size)不支持空格问题

This commit is contained in:
Looly 2023-10-18 14:42:22 +08:00
parent 733c043c0a
commit 85feecc9e9
3 changed files with 9 additions and 4 deletions

View File

@ -14,12 +14,10 @@
* 【cron 】 修复Cron表达式range解析错误问题issue#I82CSH@Gitee
* 【core 】 修复VersionComparator在极端数据排序时候违反了自反性问题issue#I81N3H@Gitee
* 【json 】 修复JSONStrFormatter:format函数对于转义符号处理逻辑错误问题issue#I84V6I@Gitee
<<<<<<< HEAD
* 【core 】 修复特定情况下BiMap覆盖Value后仍能通过旧Value查询到Key问题issue#I88R5M@Gitee
=======
* 【core 】 修复aop的afterException无法生效问题issue#3329@Github
* 【core 】 修复TypeUtil.getClass方法强转报错问题pr#1092@Github
>>>>>>> fd9e1efa2860ded5cf2d1be5954fd87a2a5830fe
* 【core 】 修复DataSize.parse(size)不支持空格问题issue#I88Z4Z@Gitee
-------------------------------------------------------------------------------------------------------------
# 5.8.22(2023-09-13)

View File

@ -185,7 +185,7 @@ public final class DataSize implements Comparable<DataSize> {
public static DataSize parse(CharSequence text, DataUnit defaultUnit) {
Assert.notNull(text, "Text must not be null");
try {
final Matcher matcher = PATTERN.matcher(text);
final Matcher matcher = PATTERN.matcher(StrUtil.cleanBlank(text));
Assert.state(matcher.matches(), "Does not match data size pattern");
final DataUnit unit = determineDataUnit(matcher.group(3), defaultUnit);

View File

@ -60,4 +60,11 @@ public class DataSizeUtilTest {
format = DataSizeUtil.format(1024L * 1024 * 1024 * 1024);
Assert.assertEquals("1 TB", format);
}
@Test
public void issueI88Z4ZTest() {
final String size = DataSizeUtil.format(10240000);
final long bytes = DataSize.parse(size).toBytes();
Assert.assertEquals(10244587, bytes);
}
}