Util-Linux Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] column: fix outputing empty column at the end of line
@ 2019-07-29  1:24 Yousong Zhou
  2019-07-29  8:35 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Yousong Zhou @ 2019-07-29  1:24 UTC (permalink / raw)
  To: kzak; +Cc: util-linux, Yousong Zhou, Sami Kerola

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>
---
v2 <- v1 Simplify the patch as suggested by @kerolaso.  It seems that
only local_wcstok() needs to be changed.

 tests/expected/column/table-empty-column-at-eol  | 1 +
 tests/expected/column/table-empty-column-at-eol2 | 1 +
 tests/ts/column/table                            | 8 ++++++++
 text-utils/column.c                              | 2 +-
 4 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 tests/expected/column/table-empty-column-at-eol
 create mode 100644 tests/expected/column/table-empty-column-at-eol2

diff --git a/tests/expected/column/table-empty-column-at-eol b/tests/expected/column/table-empty-column-at-eol
new file mode 100644
index 000000000..948cf947f
--- /dev/null
+++ b/tests/expected/column/table-empty-column-at-eol
@@ -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
index 000000000..7c4378506
--- /dev/null
+++ b/tests/expected/column/table-empty-column-at-eol2
@@ -0,0 +1 @@
+||
diff --git a/tests/ts/column/table b/tests/ts/column/table
index bd1f16f3f..e64dee746 100755
--- a/tests/ts/column/table
+++ b/tests/ts/column/table
@@ -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
diff --git a/text-utils/column.c b/text-utils/column.c
index 13b39537e..9d56e514c 100644
--- a/text-utils/column.c
+++ b/text-utils/column.c
@@ -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;
 	}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] column: fix outputing empty column at the end of line
  2019-07-29  1:24 [PATCH v2] column: fix outputing empty column at the end of line Yousong Zhou
@ 2019-07-29  8:35 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2019-07-29  8:35 UTC (permalink / raw)
  To: Yousong Zhou; +Cc: util-linux, Yousong Zhou, Sami Kerola

On Mon, Jul 29, 2019 at 01:24:29AM +0000, Yousong Zhou wrote:
>  tests/expected/column/table-empty-column-at-eol  | 1 +
>  tests/expected/column/table-empty-column-at-eol2 | 1 +
>  tests/ts/column/table                            | 8 ++++++++
>  text-utils/column.c                              | 2 +-
>  4 files changed, 11 insertions(+), 1 deletion(-)
>  create mode 100644 tests/expected/column/table-empty-column-at-eol
>  create mode 100644 tests/expected/column/table-empty-column-at-eol2

Applied, thanks! (and sorry for delay)

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-29  1:24 [PATCH v2] column: fix outputing empty column at the end of line Yousong Zhou
2019-07-29  8:35 ` Karel Zak

Util-Linux Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/util-linux/0 util-linux/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 util-linux util-linux/ https://lore.kernel.org/util-linux \
		util-linux@vger.kernel.org util-linux@archiver.kernel.org
	public-inbox-index util-linux


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.util-linux


AGPL code for this site: git clone https://public-inbox.org/ public-inbox