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