aboutsummaryrefslogtreecommitdiffstats
path: root/vm/vmimpl
diff options
context:
space:
mode:
authorAlexander Egorenkov <Alexander.Egorenkov@ibm.com>2020-10-01 13:16:00 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-10-02 12:10:52 +0200
commit062c9832a6cdb39bf38ad7a6dad51300a2e9a734 (patch)
treed70ada13165f07d43aa14aea49e685953f553513 /vm/vmimpl
parent9602ddf403bdf3cfd87efef14becc76f9a38b81d (diff)
vm/vmimpl/merger: remove all CRs from output
Get rid of all places stripping \r in pkg/report. And adapt all tests. Signed-off-by: Alexander Egorenkov <Alexander.Egorenkov@ibm.com>
Diffstat (limited to 'vm/vmimpl')
-rw-r--r--vm/vmimpl/merger.go7
-rw-r--r--vm/vmimpl/merger_test.go4
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)