From 488a88ec6ea781febfc675c0cc6a4ecc945e5d94 Mon Sep 17 00:00:00 2001 From: Jijie Wei Date: Tue, 7 Jul 2020 00:22:06 -0700 Subject: [PATCH] modify the bytereader to handler windows line ending. --- kyaml/kio/byteio_reader.go | 4 +++- kyaml/kio/byteio_reader_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/kyaml/kio/byteio_reader.go b/kyaml/kio/byteio_reader.go index 670fb96f5..f5ddc9e14 100644 --- a/kyaml/kio/byteio_reader.go +++ b/kyaml/kio/byteio_reader.go @@ -115,7 +115,9 @@ func (r *ByteReader) Read() ([]*yaml.RNode, error) { if err != nil { return nil, errors.Wrap(err) } - values := strings.Split(input.String(), "\n---\n") + + // replace the ending \r\n (line ending used in windows) with \n and then separate by \n---\n + values := strings.Split(strings.Replace(input.String(), "\r\n", "\n", -1), "\n---\n") index := 0 for i := range values { diff --git a/kyaml/kio/byteio_reader_test.go b/kyaml/kio/byteio_reader_test.go index 571becaab..c642affe6 100644 --- a/kyaml/kio/byteio_reader_test.go +++ b/kyaml/kio/byteio_reader_test.go @@ -299,6 +299,38 @@ metadata: SetAnnotations: map[string]string{"foo": "bar"}}, }, + // + // + // + { + name: "windows_line_ending", + input: "\r\n---\r\na: b # first resource\r\nc: d\r\n---\r\n# second resource\r\ne: f\r\ng:\r\n- h\r\n---\r\n\r\n---\r\n i: j", + expectedItems: []string{ + `a: b # first resource +c: d +metadata: + annotations: + foo: 'bar' +`, + `# second resource +e: f +g: +- h +metadata: + annotations: + foo: 'bar' +`, + `i: j +metadata: + annotations: + foo: 'bar' +`, + }, + instance: ByteReader{ + OmitReaderAnnotations: true, + SetAnnotations: map[string]string{"foo": "bar"}}, + }, + // // //