Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ public static long parseBytes(String text) throws IllegalArgumentException {
throw new NumberFormatException("text does not start with a number");
}

if(unit.startsWith(".")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest changing this to test the valid characters allowed - maybe with one or more regex's. I assume the unit should be 1 or more digits followed by a supported unit characters.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the unit is 1 or more digits followed by unit. I have changed this to use a regex. Could you take another look? Thanks!

throw new IllegalArgumentException("Memory size must be an integer value. Fractional values are not supported. Found: " + text);
}

final long value;
try {
value = Long.parseLong(number); // this throws a NumberFormatException on overflow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ void testParseInvalid() {
// negative number
assertThatThrownBy(() -> MemorySize.parseBytes("-100 bytes"))
.isInstanceOf(IllegalArgumentException.class);

// fractional number
assertThatThrownBy(() -> MemorySize.parseBytes("1.5g"))
.isInstanceOf(IllegalArgumentException.class);
}

@Test
Expand Down