mirror of
https://github.com/fmang/opustags.git
synced 2025-01-15 20:53:16 +01:00
warn about newlines and control characters
This commit is contained in:
parent
70e9b576cf
commit
46cd25f744
13
src/cli.cc
13
src/cli.cc
@ -146,6 +146,8 @@ void ot::print_comments(const std::list<std::string>& 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<std::string>& 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<std::string>& 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
10
t/opustags.t
10
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user