From 4c61dfb1cc85eeaa232ec810b260d3b0169e0829 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 8 Apr 2019 15:16:58 -0400 Subject: [PATCH] csvm: Permit all whitespace (including tabs) While tabs aren't desirable, users that are not developers will be modifying these files, and so we need to be permissive in what we want to accept. That doesn't mean that we need to forego occasional formatting, though. --- build-aux/csvm-expand | 2 +- build-aux/test/test-csvm2csv | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/build-aux/csvm-expand b/build-aux/csvm-expand index e53e5b32..74a71e9e 100755 --- a/build-aux/csvm-expand +++ b/build-aux/csvm-expand @@ -162,7 +162,7 @@ function parseline( i, m, j, me, orig ) BEGIN { # we're parsing CSVs - FS = " *, *" + FS = "[[:space:]]*,[[:space:]]*" OFS = "," has_directives = 0 diff --git a/build-aux/test/test-csvm2csv b/build-aux/test/test-csvm2csv index 04e63373..3e9bded6 100755 --- a/build-aux/test/test-csvm2csv +++ b/build-aux/test/test-csvm2csv @@ -120,6 +120,22 @@ $bar_baz-quux,$foo' run-test "$input" "$expected" } +# same as above but with whitespace +test-whitespace-including-tabs-ok() +{ + declare -r input='header, line +:foo=1 +:bar_baz-quux=2 +$foo, 1 +$bar_baz-quux, $foo' + + declare -r expected='header,line +1,1 +2,1' + + run-test "$input" "$expected" +} + test-range-delim() { @@ -305,6 +321,7 @@ test-comment \ && test-var-zero-ref \ && test-directive-stripped \ && test-no-sort \ + && test-whitespace-including-tabs-ok \ && test-fail-multi-directive \ && test-fail-unknown-var-ref \ && test-fail-non-numeric-range \ @@ -315,7 +332,7 @@ test-comment \ } # safety check -test "$testsum" -eq 15 || { +test "$testsum" -eq 16 || { echo 'error: did not run all csvm2csv tests!' >&2 exit 1 }