Don't panic on short input. (#5939)

Fixes #5935

Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
pull/5940/head
Brian Brazil 5 years ago committed by GitHub
parent 7d43feb03f
commit c66bfce8cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -44,7 +44,10 @@ func (l *openMetricsLexer) buf() []byte {
} }
func (l *openMetricsLexer) cur() byte { func (l *openMetricsLexer) cur() byte {
return l.b[l.i] if l.i < len(l.b) {
return l.b[l.i]
}
return byte(' ')
} }
// next advances the openMetricsLexer to the next character. // next advances the openMetricsLexer to the next character.

@ -419,6 +419,14 @@ func TestOMNullByteHandling(t *testing.T) {
input: "a\x00{b=\"ddd\"} 1", input: "a\x00{b=\"ddd\"} 1",
err: "expected value after metric, got \"MNAME\"", err: "expected value after metric, got \"MNAME\"",
}, },
{
input: "#",
err: "\"INVALID\" \" \" is not a valid start token",
},
{
input: "# H",
err: "\"INVALID\" \" \" is not a valid start token",
},
} }
for i, c := range cases { for i, c := range cases {

Loading…
Cancel
Save