Handle empty HELP in text parser. (#4444)

Fixes #4427

Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
This commit is contained in:
Brian Brazil 2018-08-01 13:29:58 +01:00 committed by GitHub
parent 7608ee87d0
commit 70c98a06f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 5 deletions

View file

@ -64,7 +64,7 @@ C [^\n]
<sComment>HELP[\t ]+ l.state = sMeta1; return tHelp
<sComment>TYPE[\t ]+ l.state = sMeta1; return tType
<sMeta1>{M}({M}|{D})* l.state = sMeta2; return tMName
<sMeta2>{C}+ l.state = sInit; return tText
<sMeta2>{C}* l.state = sInit; return tText
{M}({M}|{D})* l.state = sValue; return tMName
<sValue>\{ l.state = sLabels; return tBraceOpen

View file

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

View file

@ -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)
}

View file

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