Browse Source

Prevent lexer from seeking to next rune after lexing escape sequence. (#8517)

* Prevent lexer from seeking to next rune after lexing escape sequence.

Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
pull/8523/head
Danny Kopping 4 years ago committed by GitHub
parent
commit
42a0e0acad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      promql/parser/lex.go
  2. 10
      promql/parser/parse_test.go

6
promql/parser/lex.go

@ -583,8 +583,12 @@ func lexEscape(l *Lexer) stateFn {
return lexString
}
x = x*base + d
ch = l.next()
n--
// Don't seek after last rune.
if n > 0 {
ch = l.next()
}
}
if x > max || 0xD800 <= x && x < 0xE000 {

10
promql/parser/parse_test.go

@ -3274,6 +3274,16 @@ var testSeries = []struct {
input: `my_metric{a="b"} 1 2 3 `,
expectedMetric: labels.FromStrings(labels.MetricName, "my_metric", "a", "b"),
expectedValues: newSeq(1, 2, 3),
}, {
// Handle escaped unicode characters as whole label values.
input: `my_metric{a="\u70ac"} 1 2 3`,
expectedMetric: labels.FromStrings(labels.MetricName, "my_metric", "a", ``),
expectedValues: newSeq(1, 2, 3),
}, {
// Handle escaped unicode characters as partial label values.
input: `my_metric{a="\u70ac = torch"} 1 2 3`,
expectedMetric: labels.FromStrings(labels.MetricName, "my_metric", "a", `炬 = torch`),
expectedValues: newSeq(1, 2, 3),
}, {
input: `my_metric{a="b"} -3-3 -3`,
fail: true,

Loading…
Cancel
Save