From 3ed89ae9324026660dfefb5e482e91b8acc5262d Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Sat, 9 Jan 2016 01:38:30 +0000 Subject: wc: avoid ambiguous output with '\n' in file names * src/wc.c (write_counts): Shell escape the file name if it contains '\n' so only a single line per file is output. * tests/misc/wc-files0.sh: Add a test case. * NEWS: Mention the improvement. --- tests/misc/wc-files0.sh | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/misc/wc-files0.sh b/tests/misc/wc-files0.sh index b6a204c1c..4562e6a4e 100755 --- a/tests/misc/wc-files0.sh +++ b/tests/misc/wc-files0.sh @@ -40,4 +40,12 @@ if test "$fail" = ''; then compare exp out || fail=1 fi +# Ensure file name containing new lines are output on a single line +nlname='1 +2' +touch "$nlname" || framework_failure_ +printf '%s\0' "$nlname" | wc --files0-from=- > out || fail=1 +printf '%s\n' "0 0 0 '1'$'\\n''2'" > exp || framework_failure_ +compare exp out || fail=1 + Exit $fail -- cgit v1.2.3-54-g00ecf