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

Fixes #5935

Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
This commit is contained in:
Brian Brazil 2019-08-23 15:44:16 +01:00 committed by GitHub
parent 7d43feb03f
commit c66bfce8cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

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

View file

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