Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion promql/parser/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions promql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down