Skip to content

Commit

Permalink
Correct bug handling final lines without newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
donatj committed Sep 2, 2020
1 parent 39e83fb commit 66f4d13
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions unic.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ func (u *Filter) Exec(input io.Reader, unique, repeated io.Writer) error {
reader := bufio.NewReader(input)

for {
text, err := reader.ReadBytes('\n')
if err == io.EOF {
return nil
} else if err != nil {
return err
text, readErr := reader.ReadBytes('\n')
if readErr == io.EOF {
if len(text) == 0 {
return nil
}

text = append(text, '\n')
} else if readErr != nil {
return readErr
}

cmptxt := text
Expand All @@ -88,5 +92,9 @@ func (u *Filter) Exec(input io.Reader, unique, repeated io.Writer) error {
}

cf.InsertUnique(cmptxt)

if readErr == io.EOF {
return nil
}
}
}

0 comments on commit 66f4d13

Please sign in to comment.