diff --git a/pkg/lib/file_readers.go b/pkg/lib/file_readers.go index a348ff900..d4d3f60be 100644 --- a/pkg/lib/file_readers.go +++ b/pkg/lib/file_readers.go @@ -128,21 +128,24 @@ func openPrepipedHandleForRead( // Avoids shell-injection cases by replacing single-quote with backslash // single-quote and double-quote with backslack double-quote, then wrapping the // entire result in initial and final single-quote. -// -// TODO: test on Windows. Maybe needs move to pkg/platform. +// Also wraps in single quotes in case the filename has whitespace in it func escapeFileNameForPopen(filename string) string { var buffer bytes.Buffer - foundQuote := false + foundQuoteOrSpace := false for _, c := range filename { if c == '\'' || c == '"' { buffer.WriteRune('\'') buffer.WriteRune(c) buffer.WriteRune('\'') + foundQuoteOrSpace = true + } else if c == ' ' { + buffer.WriteRune(c) + foundQuoteOrSpace = true } else { buffer.WriteRune(c) } } - if foundQuote { + if foundQuoteOrSpace { return "'" + buffer.String() + "'" } else { return buffer.String() diff --git a/test/cases/non-windows/io-compressed-input/0017/cmd b/test/cases/non-windows/io-compressed-input/0017/cmd new file mode 100644 index 000000000..71f61cc5e --- /dev/null +++ b/test/cases/non-windows/io-compressed-input/0017/cmd @@ -0,0 +1 @@ +mlr --csv cat test/input/whitespace*.csv diff --git a/test/cases/non-windows/io-compressed-input/0017/experr b/test/cases/non-windows/io-compressed-input/0017/experr new file mode 100644 index 000000000..e69de29bb diff --git a/test/cases/non-windows/io-compressed-input/0017/expout b/test/cases/non-windows/io-compressed-input/0017/expout new file mode 100644 index 000000000..88700c714 --- /dev/null +++ b/test/cases/non-windows/io-compressed-input/0017/expout @@ -0,0 +1,3 @@ +a,b,c +1,2,3 +4,5,6 diff --git a/test/input/whitespace 1.csv b/test/input/whitespace 1.csv new file mode 100644 index 000000000..bfde6bfa0 --- /dev/null +++ b/test/input/whitespace 1.csv @@ -0,0 +1,2 @@ +a,b,c +1,2,3 diff --git a/test/input/whitespace 2.csv b/test/input/whitespace 2.csv new file mode 100644 index 000000000..a9411aa9d --- /dev/null +++ b/test/input/whitespace 2.csv @@ -0,0 +1,2 @@ +a,b,c +4,5,6