Skip to content

Commit

Permalink
improve quota value regex
Browse files Browse the repository at this point in the history
  • Loading branch information
talal committed Jun 13, 2019
1 parent 3298468 commit 21772a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions internal/core/parse_quotas.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ type baseUnitsSetter interface {
}

// Reference:
// matchList == [<full-match>, <service>, <resource>, <value>, <unit>?, (:<comment>)?, <comment>?]
var quotaValueRx = regexp.MustCompile(`^([a-zA-Z]+)/([a-zA-Z]+)=(\d*\.?\d+)([a-zA-Z]+)?(:(.*))?$`)
// matchList == [<full-match>, <service>, <resource>, <value>, <unit>?, <comment>?]
var quotaValueRx = regexp.MustCompile(`^([^:/=]+)/([^:/=]+)=(\d*\.?\d+)([a-zA-Z]+)?(?::(.*))?$`)

// ParseRawQuotas parses the raw quota values given at the command line to a
// Quotas map.
Expand Down Expand Up @@ -103,7 +103,7 @@ func ParseRawQuotas(limesV1 *gophercloud.ServiceClient, s baseUnitsSetter, rq Ra
service: matchList[1],
resource: matchList[2],
value: matchList[3],
comment: matchList[6],
comment: matchList[5],
}

givenUnit := matchList[4]
Expand Down
9 changes: 5 additions & 4 deletions internal/core/parse_quotas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ func TestQuotaValueRx(t *testing.T) {
in string
match bool
}{
{"service/resource=123456", true},
{"service/resource=123456:comment", true},
{"ser1vice/reso-urce=123456", true},
{"serv.ice/reso\\urce=123456:comment", true},
{"service/resource=123.456Unit", true},
{"service/resource=.456Unit:comment", true},

{"serv1ce/resource=123", false},
{"service/re3ource=123", false},
{"serv/ice/resource=123", false},
{"service/resou=rce=123", false},
{"service/reso:urce=123", false},
{"service?resource=123", false},
{"service/resource?123", false},
{"service/resource=g123", false},
Expand Down

0 comments on commit 21772a0

Please sign in to comment.