Skip to content

Commit

Permalink
RecordReader: fix regex reading even more
Browse files Browse the repository at this point in the history
The re type was not in empty, meaning it was not tracked properly and
well, things fell apart from there.
  • Loading branch information
twmb committed May 5, 2022
1 parent f8f480d commit 41284b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/kgo/record_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,8 @@ func (r *readKind) empty() bool {
r.size == 0 &&
r.sizefn == nil &&
r.handoff == nil &&
r.delim == nil
r.delim == nil &&
r.re == nil
}

type readParse struct {
Expand Down Expand Up @@ -1461,6 +1462,7 @@ func (r *RecordReader) next(rec *Record) error {
default:
err = r.readDelim(fn.read.delim) // we *always* fall back to delim parsing
}

switch err {
default:
return err
Expand Down
16 changes: 16 additions & 0 deletions pkg/kgo/record_formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,22 @@ func TestRecordReader(t *testing.T) {
},
},

{
layout: `%v{re#...?#}\n`,
in: "abc\n",
exp: []*Record{
StringRecord("abc"),
},
},

{
layout: `%v{re#...?#}\n`,
in: "ab\n",
exp: []*Record{
StringRecord("ab"),
},
},

{
layout: `%v{re#....#}`,
in: "abc123",
Expand Down

0 comments on commit 41284b3

Please sign in to comment.