Introduce lenient parsing in DataSize regarding whitespace
Prior to this commit, a DataSize input string could not be parsed if it contained any whitespace. With this commit, a DataSize input string can contain leading, trailing, or 'in between' whitespace. For example, the following will be parsed to the same DataSize value. - "1024B" - "1024 B" - " 1024B " - " 1024 B " Closes gh-28643
This commit is contained in:
@@ -174,7 +174,7 @@ public final class DataSize implements Comparable<DataSize>, Serializable {
|
||||
public static DataSize parse(CharSequence text, @Nullable DataUnit defaultUnit) {
|
||||
Assert.notNull(text, "Text must not be null");
|
||||
try {
|
||||
Matcher matcher = DataSizeUtils.PATTERN.matcher(text);
|
||||
Matcher matcher = DataSizeUtils.PATTERN.matcher(StringUtils.trimAllWhitespace(text));
|
||||
Assert.state(matcher.matches(), "Does not match data size pattern");
|
||||
DataUnit unit = DataSizeUtils.determineDataUnit(matcher.group(2), defaultUnit);
|
||||
long amount = Long.parseLong(matcher.group(1));
|
||||
|
||||
Reference in New Issue
Block a user