From 46cd25f744a02707c1dc21a4e7a5d9080b536034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano-Tarumi?= Date: Sun, 16 Dec 2018 12:36:37 -0500 Subject: [PATCH] warn about newlines and control characters --- src/cli.cc | 13 +++++++++++++ t/opustags.t | 10 +++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/cli.cc b/src/cli.cc index 54cea4a..80964fd 100644 --- a/src/cli.cc +++ b/src/cli.cc @@ -146,6 +146,8 @@ void ot::print_comments(const std::list& comments, FILE* output) std::string local; bool info_lost = false; bool bad_comments = false; + bool has_newline = false; + bool has_control = false; for (const std::string& comment : comments) { ot::status rc = from_utf8(comment, local); if (rc == ot::st::information_lost) { @@ -154,6 +156,12 @@ void ot::print_comments(const std::list& comments, FILE* output) bad_comments = true; continue; } + for (unsigned char c : comment) { + if (c == '\n') + has_newline = true; + else if (c < 0x20) + has_control = true; + } fwrite(local.data(), 1, local.size(), output); putchar('\n'); } @@ -161,6 +169,11 @@ void ot::print_comments(const std::list& comments, FILE* output) fputs("warning: Some tags have been transliterated to your system encoding.\n", stderr); if (bad_comments) fputs("warning: Some tags are not properly encoded and have not been displayed.\n", stderr); + if (has_newline) + fputs("warning: Some tags contain newline characters. " + "These are not supported by --set-all.\n", stderr); + if (has_control) + fputs("warning: Some tags contain control characters.\n", stderr); } /** diff --git a/t/opustags.t b/t/opustags.t index d43814c..563575b 100755 --- a/t/opustags.t +++ b/t/opustags.t @@ -8,7 +8,7 @@ use strict; use warnings; use utf8; -use Test::More tests => 33; +use Test::More tests => 34; use Digest::MD5; use File::Basename; @@ -143,6 +143,14 @@ error: Invalid comment 'FOO'. EOF is(md5('out.opus'), '66780307a6081523dc9040f3c47b0448', 'the file did not change'); +is_deeply(opustags('out.opus', '-D', '-a', "X=foo\nbar\tquux"), [<<'END_OUT', <<'END_ERR', 0], 'control characters'); +X=foo +bar quux +END_OUT +warning: Some tags contain newline characters. These are not supported by --set-all. +warning: Some tags contain control characters. +END_ERR + is_deeply(opustags(qw(-i out.opus -s fatal=yes -s FOO -s BAR)), ['', <<'EOF', 256], 'bad tag with --set'); error: Invalid comment 'FOO'. EOF