fixes space issue in duration range promql (#6295)

* fix space issue in duration range promql

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>

* updated logic

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>

* fixed lexer to skip over the spaces

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>

* added unittests for updated lexer

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>

* added unittests for updated lexer

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>
This commit is contained in:
Harkishen Singh 2019-11-11 14:26:24 +05:30 committed by Julius Volz
parent 2d8b6c7792
commit 37d666949c
2 changed files with 41 additions and 0 deletions

View file

@ -550,6 +550,9 @@ func lexStatements(l *lexer) stateFn {
}
l.gotColon = false
l.emit(ItemLeftBracket)
if isSpace(l.peek()) {
skipSpaces(l)
}
l.bracketOpen = true
return lexDuration
case r == ']':
@ -715,6 +718,14 @@ func digitVal(ch rune) int {
return 16 // Larger than any legal digit val.
}
// skipSpaces skips the spaces until a non-space is encountered.
func skipSpaces(l *lexer) {
for isSpace(l.peek()) {
l.next()
}
l.ignore()
}
// lexString scans a quoted string. The initial quote has already been seen.
func lexString(l *lexer) stateFn {
Loop:

View file

@ -49,6 +49,27 @@ var tests = []struct {
{ItemDuration, 1, `5m`},
{ItemRightBracket, 3, `]`},
},
}, {
input: "[ 5m]",
expected: []item{
{ItemLeftBracket, 0, `[`},
{ItemDuration, 2, `5m`},
{ItemRightBracket, 4, `]`},
},
}, {
input: "[ 5m]",
expected: []item{
{ItemLeftBracket, 0, `[`},
{ItemDuration, 3, `5m`},
{ItemRightBracket, 5, `]`},
},
}, {
input: "[ 5m ]",
expected: []item{
{ItemLeftBracket, 0, `[`},
{ItemDuration, 3, `5m`},
{ItemRightBracket, 6, `]`},
},
}, {
input: "\r\n\r",
expected: []item{},
@ -633,6 +654,15 @@ var tests = []struct {
{ItemRightBracket, 60, `]`},
},
},
{
input: `test:name[ 5m]`,
expected: []item{
{ItemMetricIdentifier, 0, `test:name`},
{ItemLeftBracket, 9, `[`},
{ItemDuration, 11, `5m`},
{ItemRightBracket, 13, `]`},
},
},
{
input: `test:name{o:n!~"bar"}[4m:4s]`,
fail: true,