diff --git a/src/cli.cc b/src/cli.cc index fd82b28..ea2a92b 100644 --- a/src/cli.cc +++ b/src/cli.cc @@ -58,6 +58,7 @@ ot::status ot::parse_options(int argc, char** argv, ot::options& opt) { static ot::encoding_converter to_utf8("", "UTF-8"); std::string utf8; + std::string::size_type equal; ot::status rc; opt = {}; if (argc == 1) @@ -96,10 +97,10 @@ ot::status ot::parse_options(int argc, char** argv, ot::options& opt) rc = to_utf8(optarg, strlen(optarg), utf8); if (rc != ot::st::ok) return {st::bad_arguments, "Could not encode argument into UTF-8: " + rc.message}; - if (strchr(utf8.c_str(), '=') == NULL) - return {st::bad_arguments, "Invalid comment '"s + optarg + "'."}; + if ((equal = utf8.find('=')) == std::string::npos) + return {st::bad_arguments, "Comment does not contain an equal sign: "s + optarg + "."}; if (c == 's') - opt.to_delete.emplace_back(utf8); + opt.to_delete.emplace_back(utf8.substr(0, equal)); opt.to_add.emplace_back(std::move(utf8)); break; case 'S': diff --git a/t/cli.cc b/t/cli.cc index f8e0ddb..50713f7 100644 --- a/t/cli.cc +++ b/t/cli.cc @@ -52,7 +52,7 @@ void check_good_arguments() opt = parse({"opustags", "x", "--output", "y", "-D", "-s", "X=Y Z"}); if (opt.path_in != "x" || opt.path_out != "y" || !opt.delete_all || opt.overwrite || - opt.to_delete.size() != 1 || opt.to_delete[0] != "X=Y Z" || + opt.to_delete.size() != 1 || opt.to_delete[0] != "X" || opt.to_add.size() != 1 || opt.to_add[0] != "X=Y Z") throw failure("unexpected option parsing result for case #1"); @@ -75,8 +75,8 @@ void check_bad_arguments() error_case({"opustags"}, "No arguments specified. Use -h for help.", "no arguments"); error_case({"opustags", "--output", ""}, "Output file path cannot be empty.", "empty output path"); error_case({"opustags", "--delete", "X="}, "Invalid field name 'X='.", "bad field name for -d"); - error_case({"opustags", "-a", "X"}, "Invalid comment 'X'.", "bad comment for -a"); - error_case({"opustags", "--set", "X"}, "Invalid comment 'X'.", "bad comment for --set"); + error_case({"opustags", "-a", "X"}, "Comment does not contain an equal sign: X.", "bad comment for -a"); + error_case({"opustags", "--set", "X"}, "Comment does not contain an equal sign: X.", "bad comment for --set"); error_case({"opustags", "-a"}, "Missing value for option '-a'.", "short option with missing value"); error_case({"opustags", "--add"}, "Missing value for option '--add'.", "long option with missing value"); error_case({"opustags", "-x"}, "Unrecognized option '-x'.", "unrecognized short option"); diff --git a/t/opustags.t b/t/opustags.t index 4e1942f..c8fe613 100755 --- a/t/opustags.t +++ b/t/opustags.t @@ -139,7 +139,7 @@ EOF is(md5('out.opus'), '66780307a6081523dc9040f3c47b0448', 'the file did not change'); is_deeply(opustags(qw(-i out.opus -a fatal=yes -a FOO -a BAR)), ['', <<'EOF', 256], 'bad tag with --add'); -error: Invalid comment 'FOO'. +error: Comment does not contain an equal sign: FOO. EOF is(md5('out.opus'), '66780307a6081523dc9040f3c47b0448', 'the file did not change'); @@ -152,7 +152,7 @@ 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'. +error: Comment does not contain an equal sign: FOO. EOF is(md5('out.opus'), '66780307a6081523dc9040f3c47b0448', 'the file did not change');