Browse Source

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
commit
c66bfce8cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      pkg/textparse/openmetricsparse.go
  2. 8
      pkg/textparse/openmetricsparse_test.go

5
pkg/textparse/openmetricsparse.go

@ -44,7 +44,10 @@ func (l *openMetricsLexer) buf() []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.

8
pkg/textparse/openmetricsparse_test.go

@ -419,6 +419,14 @@ func TestOMNullByteHandling(t *testing.T) {
input: "a\x00{b=\"ddd\"} 1",
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 {

Loading…
Cancel
Save