]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
column: fix outputing empty column at the end of line
authorYousong Zhou <yszhou4tech@gmail.com>
Mon, 29 Jul 2019 01:24:29 +0000 (01:24 +0000)
committerKarel Zak <kzak@redhat.com>
Mon, 29 Jul 2019 08:33:58 +0000 (10:33 +0200)
The following commands manifests the problem.  In old versions before
commit 4762ae9d60 ("column: use libsmartcols for --table"), both of them
should output with 2 "|"

echo '||'  | column -o '|' -s '|' -t
echo '|| ' | column -o '|' -s '|' -t

Fixes: 4762ae9d60 ("column: use libsmartcols for --table")
Signed-off-by: Yousong Zhou <zhouyousong@yunionyun.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
tests/expected/column/table-empty-column-at-eol [new file with mode: 0644]
tests/expected/column/table-empty-column-at-eol2 [new file with mode: 0644]
tests/ts/column/table
text-utils/column.c

diff --git a/tests/expected/column/table-empty-column-at-eol b/tests/expected/column/table-empty-column-at-eol
new file mode 100644 (file)
index 0000000..948cf94
--- /dev/null
@@ -0,0 +1 @@
+|
diff --git a/tests/expected/column/table-empty-column-at-eol2 b/tests/expected/column/table-empty-column-at-eol2
new file mode 100644 (file)
index 0000000..7c43785
--- /dev/null
@@ -0,0 +1 @@
+||
index bd1f16f3fff0ce2ab06ff4d8db899c1c88c68bf3..e64dee746e95c44f53b15aaa66dcce16c5207abc 100755 (executable)
@@ -116,4 +116,12 @@ ts_init_subtest "empty-column"
 printf ':a:b\n' | $TS_CMD_COLUMN --table --separator ':' --output-separator  ':' >> $TS_OUTPUT 2>&1
 ts_finalize_subtest
 
+ts_init_subtest "empty-column-at-eol"
+printf '|' | $TS_CMD_COLUMN --separator '|' --output-separator '|' --table >> $TS_OUTPUT 2>&1
+ts_finalize_subtest
+
+ts_init_subtest "empty-column-at-eol2"
+printf '||' | $TS_CMD_COLUMN --separator '|' --output-separator '|' --table >> $TS_OUTPUT 2>&1
+ts_finalize_subtest
+
 ts_finalize
index 13b39537e210cacf03223723e568e79540a05fdf..9d56e514c30586c80507afab58965346ec495415 100644 (file)
@@ -169,7 +169,7 @@ static wchar_t *local_wcstok(wchar_t *p, const wchar_t *separator, int greedy, w
                return strtok_r(p, separator, state);
 #endif
        if (!p) {
-               if (!*state || !**state)
+               if (!*state)
                        return NULL;
                p = *state;
        }