From 88f5abbe1898a4e56b9aa32088ff135e7dddce87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=AC=E5=9F=8E=E9=83=AD=E5=B0=91?= <39666162+GuoFlight@users.noreply.github.com> Date: Tue, 12 May 2026 15:28:23 +0800 Subject: [PATCH] fix When parsing {}, the parser enters startLabelName state with p.currentMetric == nil, causing the crash. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 京城郭少 <39666162+GuoFlight@users.noreply.github.com> --- expfmt/text_parse.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/expfmt/text_parse.go b/expfmt/text_parse.go index 00c8841a..a60cf1d7 100644 --- a/expfmt/text_parse.go +++ b/expfmt/text_parse.go @@ -339,6 +339,11 @@ func (p *TextParser) startLabelName() stateFn { return nil // Unexpected end of input. } if p.currentByte == '}' { + if p.currentMetric == nil { + p.parseError("unexpected '}' without metric name") + p.currentLabelPairs = nil + return nil + } p.currentMetric.Label = append(p.currentMetric.Label, p.currentLabelPairs...) p.currentLabelPairs = nil if p.skipBlankTab(); p.err != nil {