diff --git a/pkg/textparse/lex.l b/pkg/textparse/lex.l index a6b728c71a..590c7774d4 100644 --- a/pkg/textparse/lex.l +++ b/pkg/textparse/lex.l @@ -64,7 +64,7 @@ C [^\n] HELP[\t ]+ l.state = sMeta1; return tHelp TYPE[\t ]+ l.state = sMeta1; return tType {M}({M}|{D})* l.state = sMeta2; return tMName -{C}+ l.state = sInit; return tText +{C}* l.state = sInit; return tText {M}({M}|{D})* l.state = sValue; return tMName \{ l.state = sLabels; return tBraceOpen diff --git a/pkg/textparse/lex.l.go b/pkg/textparse/lex.l.go index 33a6a9fce1..5ddfb562ef 100644 --- a/pkg/textparse/lex.l.go +++ b/pkg/textparse/lex.l.go @@ -1,4 +1,4 @@ -// Code generated by golex. DO NOT EDIT. +// CAUTION: Generated file - DO NOT EDIT. // Copyright 2017 The Prometheus Authors // Licensed under the Apache License, Version 2.0 (the "License"); @@ -260,7 +260,7 @@ yystate21: yystart21: switch { default: - goto yyabort + goto yyrule9 case c == '\t' || c == ' ': goto yystate23 case c >= '\x01' && c <= '\b' || c >= '\v' && c <= '\x1f' || c >= '!' && c <= 'ΓΏ': @@ -463,7 +463,7 @@ yyrule8: // {M}({M}|{D})* return tMName goto yystate0 } -yyrule9: // {C}+ +yyrule9: // {C}* { l.state = sInit return tText diff --git a/pkg/textparse/parse.go b/pkg/textparse/parse.go index 9bd515ab73..f7db282fc3 100644 --- a/pkg/textparse/parse.go +++ b/pkg/textparse/parse.go @@ -281,7 +281,11 @@ func (p *Parser) Next() (Entry, error) { } switch t := p.nextToken(); t { case tText: - p.text = p.l.buf()[1:] + if len(p.l.buf()) > 1 { + p.text = p.l.buf()[1:] + } else { + p.text = []byte{} + } default: return EntryInvalid, parseError("expected text in HELP", t) } diff --git a/pkg/textparse/parse_test.go b/pkg/textparse/parse_test.go index 3852bfdf14..07d4b0c891 100644 --- a/pkg/textparse/parse_test.go +++ b/pkg/textparse/parse_test.go @@ -39,6 +39,8 @@ go_gc_duration_seconds{ quantile="0.9", a="b"} 8.3835e-05 # # comment with escaped \n newline # comment with escaped \ escape character +# HELP nohelp1 +# HELP nohelp2 go_gc_duration_seconds{ quantile="1.0", a="b" } 8.3835e-05 go_gc_duration_seconds { quantile="1.0", a="b" } 8.3835e-05 go_gc_duration_seconds { quantile= "1.0", a= "b", } 8.3835e-05 @@ -99,6 +101,12 @@ testmetric{label="\"bar\""} 1` comment: "# comment with escaped \\n newline", }, { comment: "# comment with escaped \\ escape character", + }, { + m: "nohelp1", + help: "", + }, { + m: "nohelp2", + help: "", }, { m: `go_gc_duration_seconds{ quantile="1.0", a="b" }`, v: 8.3835e-05,