Skip to content

Commit ba74f4d

Browse files
CuriousCorrelationroboquat
authored andcommitted
[ws-daemon] Fix quota size regex's false positives
1 parent 3639c61 commit ba74f4d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

components/ws-daemon/pkg/quota/size.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const (
3131
)
3232

3333
var (
34-
sizeRegexp = regexp.MustCompile(`(\d+)(k|m|g|t)?`)
34+
sizeRegexp = regexp.MustCompile(`^(\d+)(k|m|g|t)?$`)
3535

3636
// ErrInvalidSize is returned by ParseSize if input was not a valid size
3737
ErrInvalidSize = errors.New("invalid size")

components/ws-daemon/pkg/quota/size_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func TestParseSize(t *testing.T) {
2323
{"42m", 42 * quota.Megabyte, nil},
2424
{"42g", 42 * quota.Gigabyte, nil},
2525
{"42t", 42 * quota.Terabyte, nil},
26-
// This test should fail but doesn't because match somehow matches the regexp
27-
// {"-42m", 0, quota.ErrInvalidSize},
26+
{"-42m", 0, quota.ErrInvalidSize},
27+
{"ab-42mcd", 0, quota.ErrInvalidSize},
2828
{"abc", 0, quota.ErrInvalidSize},
2929
{"99999999999999999999999999999999999999999999999999999999999999999999999999999999", 0, quota.ErrInvalidSize},
3030
}

0 commit comments

Comments
 (0)