]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
column: use \x<hex> for invalid multibyte seq.
authorKarel Zak <kzak@redhat.com>
Wed, 22 Nov 2017 13:43:36 +0000 (14:43 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 14 Dec 2017 14:39:50 +0000 (15:39 +0100)
Addresses: https://github.com/karelzak/util-linux/issues/542
Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/column.1
text-utils/column.c

index 6baa0464a3f0da1b6d7522efe403873730fb031a..c6da5615c64529b8b1c01035ac5ec9b18c48ba45 100644 (file)
@@ -54,7 +54,7 @@ mode is enabled by option \fB-t, \-\-table\fP and columns formatting is
 possible to modify by \fB\-\-table-*\fP options.  Use this mode if not sure.
 .PP
 Input is taken from \fIfile\fR, or otherwise from standard input.  Empty lines
-are ignored.
+are ignored and all invalid multibyte sequences are encoded by \\x<hex> convention.
 .PP
 .SH OPTIONS
 The argument \fIcolumns\fP for \fB\-\-table-*\fP options is comma separated
index d34cfc3f0d6aeed4b55a70cb4701501c82e181c9..88122a0e7d05bda2aea6650e040327d0405fbe9f 100644 (file)
@@ -52,6 +52,7 @@
 #include "ttyutils.h"
 #include "strv.h"
 #include "optutils.h"
+#include "mbsalign.h"
 
 #include "libsmartcols.h"
 
@@ -458,8 +459,18 @@ static int read_input(struct column_control *ctl, FILE *fp)
                        continue;
 
                wcs = mbs_to_wcs(str);
-               if (!wcs)
-                       err(EXIT_FAILURE, _("read failed"));
+               if (!wcs) {
+                       /*
+                        * Convert broken sequences to \x<hex> and continue.
+                        */
+                       size_t tmpsz = 0;
+                       char *tmp = mbs_invalid_encode(str, &tmpsz);
+
+                       if (!tmp)
+                               err(EXIT_FAILURE, _("read failed"));
+                       wcs = mbs_to_wcs(tmp);
+                       free(tmp);
+               }
 
                switch (ctl->mode) {
                case COLUMN_MODE_TABLE:
@@ -590,6 +601,7 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -s, --separator <string>         possible table delimiters\n"), out);
        fputs(_(" -x, --fillrows                   fill rows before columns\n"), out);
 
+
        fputs(USAGE_SEPARATOR, out);
        printf(USAGE_HELP_OPTIONS(34));
        printf(USAGE_MAN_TAIL("column(1)"));