diff --git a/lexer.go b/lexer.go index c91f863..93fb0d3 100644 --- a/lexer.go +++ b/lexer.go @@ -571,6 +571,7 @@ func DurationValue(s string, step int64) (int64, error) { } isMinus := false d := float64(0) + s = strings.ToLower(s) for len(s) > 0 { n := scanSingleDuration(s, true) if n <= 0 { @@ -656,6 +657,7 @@ func scanSingleDuration(s string, canBeNegative bool) int { if len(s) == 0 { return -1 } + s = strings.ToLower(s) i := 0 if s[0] == '-' && canBeNegative { i++ diff --git a/lexer_test.go b/lexer_test.go index 47cea27..1ab9f83 100644 --- a/lexer_test.go +++ b/lexer_test.go @@ -513,6 +513,14 @@ func TestPositiveDurationSuccess(t *testing.T) { f("1.23", 45, 1230) f("0.56", 12, 560) f(".523e2", 21, 52300) + + // duration suffixes in mixed case + f("1Ms", 45, 1) + f("1mS", 45, 1) + f("1M", 45, 1*60*1000) + f("1H", 45, 1*60*60*1000) + f("1D", 45, 1*24*60*60*1000) + f("1Y", 45, 1*365*24*60*60*1000) } func TestPositiveDurationError(t *testing.T) { @@ -588,6 +596,13 @@ func TestDurationSuccess(t *testing.T) { f("1.23", 45, 1230) f("-0.56", 12, -560) f("-.523e2", 21, -52300) + + f("1Ms", 10, 1) + f("1mS", 10, 1) + f("1M", 10, 60*1000) + f("1H", 10, 1*60*60*1000) + f("1D", 10, 1*24*60*60*1000) + f("1Y", 10, 1*365*24*60*60*1000) } func TestDurationError(t *testing.T) { diff --git a/parser.go b/parser.go index 9b92dba..fcdf8ff 100644 --- a/parser.go +++ b/parser.go @@ -1341,6 +1341,7 @@ func (p *parser) parsePositiveDuration() (*DurationExpr, error) { return nil, fmt.Errorf(`duration: parse error: %s`, err) } } + de := &DurationExpr{ s: s, } diff --git a/parser_test.go b/parser_test.go index 4245469..dd7d523 100644 --- a/parser_test.go +++ b/parser_test.go @@ -309,6 +309,15 @@ func TestParseSuccess(t *testing.T) { // funcName with escape chars same(`foo\(ba\-r()`) + // duration converts to lower case + another(`{}[5m:3S]`, `{}[5m:3S]`) + another(`{}[5H:]`, `{}[5H:]`) + another(`{}[5M:3s]`, `{}[5M:3s]`) + another(`m[10M]`, `m[10M]`) + another(`m[10MS]`, `m[10MS]`) + another(`foo offset 5M`, `foo offset 5M`) + another(`foo offset 5S`, `foo offset 5S`) + // aggrFuncExpr same(`sum(http_server_request) by ()`) same(`sum(http_server_request) by (job)`)