mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
修复DataSize.parse(size)不支持空格问题
This commit is contained in:
parent
3ce8b1dc0b
commit
d5c6a6d217
@ -197,7 +197,7 @@ public final class DataSize implements Comparable<DataSize> {
|
||||
public static DataSize parse(final CharSequence text, final 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);
|
||||
|
@ -72,4 +72,11 @@ public class DataSizeUtilTest {
|
||||
format = DataSizeUtil.format(1024L * 1024 * 1024 * 1024);
|
||||
Assertions.assertEquals("1 TB", format);
|
||||
}
|
||||
|
||||
@Test
|
||||
void issueI88Z4ZTest() {
|
||||
final String size = DataSizeUtil.format(10240000);
|
||||
final long bytes = DataSize.parse(size).toBytes();
|
||||
Assertions.assertEquals(10244587, bytes);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user