Skip to content

Commit

Permalink
remove other control codes from valid names
Browse files Browse the repository at this point in the history
  • Loading branch information
phlptp committed Nov 11, 2023
1 parent a76ff99 commit 22c7e8d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions include/CLI/StringTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ CLI11_INLINE std::ostream &format_aliases(std::ostream &out, const std::vector<s
/// Verify the first character of an option
/// - is a trigger character, ! has special meaning and new lines would just be annoying to deal with
template <typename T> bool valid_first_char(T c) {
return ((c != '-') && (c != '!') && (c != ' ') && (c != '\n') && (c != '\0'));
return ((c != '-') && (static_cast<unsigned char>(c) > 33)); // space and '!' not allowed
}

/// Verify following characters of an option
template <typename T> bool valid_later_char(T c) {
// = and : are value separators, { has special meaning for option defaults,
// and \n and '\0' would just be annoying to deal with in many places allowing space here has too much potential for
// and control codes other than tab would just be annoying to deal with in many places allowing space here has too much potential for
// inadvertent entry errors and bugs
return ((c != '=') && (c != ':') && (c != '{') && (c != ' ') && (c != '\n') && (c != '\0'));
return ((c != '=') && (c != ':') && (c != '{') && ((static_cast<unsigned char>(c) > 32)||c=='\t'));
}

/// Verify an option/subcommand name
Expand Down
4 changes: 2 additions & 2 deletions include/CLI/impl/App_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,13 @@ CLI11_INLINE bool App::remove_option(Option *opt) {
CLI11_INLINE App *App::add_subcommand(std::string subcommand_name, std::string subcommand_description) {
if(!subcommand_name.empty() && !detail::valid_name_string(subcommand_name)) {
if(!detail::valid_first_char(subcommand_name[0])) {
throw IncorrectConstruction("Subcommand name starts with invalid character, '!' and '-' are not allowed");
throw IncorrectConstruction("Subcommand name starts with invalid character, '!' and '-' and control characters");
}
for(auto c : subcommand_name) {
if(!detail::valid_later_char(c)) {
throw IncorrectConstruction(std::string("Subcommand name contains invalid character ('") + c +
"'), all characters are allowed except"
"'=',':','{','}', and ' '");
"'=',':','{','}', ' ', and control characters");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/FuzzFailTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ TEST_CASE("app_file_gen_fail") {
CLI::FuzzApp fuzzdata;
auto app = fuzzdata.generateApp();

int index = GENERATE(range(1, 9));
int index = GENERATE(range(1, 10));
std::string optionString, flagString;
auto parseData = loadFailureFile("fuzz_app_file_fail", index);
if(parseData.size() > 25) {
Expand Down
1 change: 1 addition & 0 deletions tests/fuzzFail/fuzz_app_file_fail9
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
=o����������p--2v��t ' �-�-

0 comments on commit 22c7e8d

Please sign in to comment.