diff options
Diffstat (limited to 'vm/vmimpl')
| -rw-r--r-- | vm/vmimpl/merger.go | 7 | ||||
| -rw-r--r-- | vm/vmimpl/merger_test.go | 4 |
2 files changed, 8 insertions, 3 deletions
diff --git a/vm/vmimpl/merger.go b/vm/vmimpl/merger.go index a61729422..3691dd0c0 100644 --- a/vm/vmimpl/merger.go +++ b/vm/vmimpl/merger.go @@ -63,7 +63,12 @@ func (merger *OutputMerger) AddDecoder(name string, r io.ReadCloser, merger.Output <- decoded // note: this can block } } - pending = append(pending, buf[:n]...) + // Remove all carriage returns. + buf := buf[:n] + if bytes.IndexByte(buf, '\r') != -1 { + buf = bytes.ReplaceAll(buf, []byte("\r"), nil) + } + pending = append(pending, buf...) if pos := bytes.LastIndexByte(pending, '\n'); pos != -1 { out := pending[:pos+1] if merger.tee != nil { diff --git a/vm/vmimpl/merger_test.go b/vm/vmimpl/merger_test.go index b8ae9dfc3..8308aff5e 100644 --- a/vm/vmimpl/merger_test.go +++ b/vm/vmimpl/merger_test.go @@ -44,13 +44,13 @@ func TestMerger(t *testing.T) { case <-time.After(10 * time.Millisecond): } - wp1.Write([]byte("333\n444")) + wp1.Write([]byte("333\n444\r")) got := string(<-merger.Output) if want := "111333\n"; got != want { t.Fatalf("bad line: '%s', want '%s'", got, want) } - wp2.Write([]byte("555\n666\n777")) + wp2.Write([]byte("555\r\n666\n\r\r777")) got = string(<-merger.Output) if want := "222555\n666\n"; got != want { t.Fatalf("bad line: '%s', want '%s'", got, want) |
