From 21772a0c3fd14a86ee2d240185179d981ceb2adc Mon Sep 17 00:00:00 2001 From: Muhammad Talal Anwar Date: Thu, 13 Jun 2019 14:16:24 +0200 Subject: [PATCH] improve quota value regex --- internal/core/parse_quotas.go | 6 +++--- internal/core/parse_quotas_test.go | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/core/parse_quotas.go b/internal/core/parse_quotas.go index e68008f4..ff50ea5d 100644 --- a/internal/core/parse_quotas.go +++ b/internal/core/parse_quotas.go @@ -73,8 +73,8 @@ type baseUnitsSetter interface { } // Reference: -// matchList == [, , , , ?, (:)?, ?] -var quotaValueRx = regexp.MustCompile(`^([a-zA-Z]+)/([a-zA-Z]+)=(\d*\.?\d+)([a-zA-Z]+)?(:(.*))?$`) +// matchList == [, , , , ?, ?] +var quotaValueRx = regexp.MustCompile(`^([^:/=]+)/([^:/=]+)=(\d*\.?\d+)([a-zA-Z]+)?(?::(.*))?$`) // ParseRawQuotas parses the raw quota values given at the command line to a // Quotas map. @@ -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] diff --git a/internal/core/parse_quotas_test.go b/internal/core/parse_quotas_test.go index c5675c8b..7bf30e2e 100644 --- a/internal/core/parse_quotas_test.go +++ b/internal/core/parse_quotas_test.go @@ -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},