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>
This commit is contained in:
Danny Kopping 2021-02-19 08:38:05 +02:00 committed by GitHub
parent 423bde533c
commit 42a0e0acad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -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 {

View File

@ -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,