From ac765869630e99e4b4aecd9a43bbb198ea52b530 Mon Sep 17 00:00:00 2001 From: Danny Kopping Date: Thu, 18 Feb 2021 14:27:37 +0200 Subject: [PATCH 1/3] Prevent lexer from seeking to next rune after lexing escape sequence. Signed-off-by: Danny Kopping --- promql/parser/lex.go | 6 +++++- promql/parser/parse_test.go | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/promql/parser/lex.go b/promql/parser/lex.go index ece762dc4da..f45451bfe27 100644 --- a/promql/parser/lex.go +++ b/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 { diff --git a/promql/parser/parse_test.go b/promql/parser/parse_test.go index 10096188af7..7e1bae716c2 100644 --- a/promql/parser/parse_test.go +++ b/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, From df8e0250a094bc6188e91847815b47aa14b0c748 Mon Sep 17 00:00:00 2001 From: Danny Kopping Date: Thu, 18 Feb 2021 15:15:59 +0200 Subject: [PATCH 2/3] Testing if CI runs tests. Signed-off-by: Danny Kopping From 57024b4474a7d6d40ba52103e45879da79763206 Mon Sep 17 00:00:00 2001 From: Danny Kopping Date: Thu, 18 Feb 2021 15:51:45 +0200 Subject: [PATCH 3/3] Fixing comment formatting Signed-off-by: Danny Kopping --- promql/parser/lex.go | 2 +- promql/parser/parse_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/promql/parser/lex.go b/promql/parser/lex.go index f45451bfe27..313bd8f88b0 100644 --- a/promql/parser/lex.go +++ b/promql/parser/lex.go @@ -585,7 +585,7 @@ func lexEscape(l *Lexer) stateFn { x = x*base + d n-- - // don't seek after last rune + // Don't seek after last rune. if n > 0 { ch = l.next() } diff --git a/promql/parser/parse_test.go b/promql/parser/parse_test.go index 7e1bae716c2..d4203c16e53 100644 --- a/promql/parser/parse_test.go +++ b/promql/parser/parse_test.go @@ -3275,12 +3275,12 @@ var testSeries = []struct { expectedMetric: labels.FromStrings(labels.MetricName, "my_metric", "a", "b"), expectedValues: newSeq(1, 2, 3), }, { - // Handle escaped unicode characters as whole label values + // 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 + // 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),