mirror of
https://github.com/johnkerl/miller.git
synced 2026-01-23 02:14:13 +00:00
Fix prepipe handling when filenames have whitespace (#1627)
* Fix prepipe handling when filenames have whitespace * unit-test data * Windows-only unit-test item * Fix Windows fails; neaten
This commit is contained in:
parent
16a898cff4
commit
1015f18e7b
6 changed files with 15 additions and 4 deletions
|
|
@ -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()
|
||||
|
|
|
|||
1
test/cases/non-windows/io-compressed-input/0017/cmd
Normal file
1
test/cases/non-windows/io-compressed-input/0017/cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
mlr --csv cat test/input/whitespace*.csv
|
||||
0
test/cases/non-windows/io-compressed-input/0017/experr
Normal file
0
test/cases/non-windows/io-compressed-input/0017/experr
Normal file
3
test/cases/non-windows/io-compressed-input/0017/expout
Normal file
3
test/cases/non-windows/io-compressed-input/0017/expout
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
a,b,c
|
||||
1,2,3
|
||||
4,5,6
|
||||
2
test/input/whitespace 1.csv
Normal file
2
test/input/whitespace 1.csv
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
a,b,c
|
||||
1,2,3
|
||||
|
2
test/input/whitespace 2.csv
Normal file
2
test/input/whitespace 2.csv
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
a,b,c
|
||||
4,5,6
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue