@@ -368,7 +368,20 @@ class App {
368368 // / Set an alias for the app
369369 App *alias (std::string app_name) {
370370 if (!detail::valid_name_string (app_name)) {
371- throw (IncorrectConstruction (" alias is not a valid name string" ));
371+ if (app_name.empty ()) {
372+ throw IncorrectConstruction (" Empty aliases are not allowed" );
373+ }
374+ if (!detail::valid_first_char (app_name[0 ])) {
375+ throw IncorrectConstruction (
376+ " Alias starts with invalid character, allowed characters are [a-zA-z0-9]+'_','?','@' " );
377+ }
378+ for (auto c : app_name) {
379+ if (!detail::valid_later_char (c)) {
380+ throw IncorrectConstruction (std::string (" Alias contains invalid character ('" ) + c +
381+ " '), allowed characters are "
382+ " [a-zA-z0-9]+'_','?','@','.','-' " );
383+ }
384+ }
372385 }
373386
374387 if (parent_ != nullptr ) {
@@ -1012,8 +1025,19 @@ class App {
10121025
10131026 // / Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag
10141027 App *add_subcommand (std::string subcommand_name = " " , std::string subcommand_description = " " ) {
1015- if (!subcommand_name.empty () && !detail::valid_name_string (subcommand_name)) {
1016- throw IncorrectConstruction (" subcommand name is not valid" );
1028+ if (!detail::valid_name_string (subcommand_name)) {
1029+ if (subcommand_name.empty ()) {
1030+ throw IncorrectConstruction (" Empty subcommand names are not allowed" );
1031+ }
1032+ if (!detail::valid_first_char (subcommand_name[0 ])) {
1033+ throw IncorrectConstruction (" Subcommand name starts with invalid character, allowed characters are [a-zA-z0-9]+'_','?','@' " );
1034+ }
1035+ for (auto c : subcommand_name) {
1036+ if (!detail::valid_later_char (c)) {
1037+ throw IncorrectConstruction (std::string (" Subcommand name contains invalid character ('" )+c+" '), allowed characters are "
1038+ " [a-zA-z0-9]+'_','?','@','.','-' " );
1039+ }
1040+ }
10171041 }
10181042 CLI::App_p subcom = std::shared_ptr<App>(new App (std::move (subcommand_description), subcommand_name, this ));
10191043 return add_subcommand (std::move (subcom));
0 commit comments