@@ -562,28 +562,26 @@ struct ConditionScope {
562562};
563563
564564static bool vcpkg_valid_identifier (const std::string &name) {
565- // prn|aux|nul|con|lpt[1-9]|com[1-9]|core|default
566- auto is_reserved = [](const std::string &s) {
567- if (s == " prn" || s == " aux" || s == " nul" || s == " con" || s == " core" || s == " default" ) {
568- return true ;
569- }
570- if (s.length () == 4 && (s.compare (0 , 3 , " lpt" ) == 0 || s.compare (0 , 3 , " com" ) == 0 ) && (s[3 ] >= ' 1' && s[3 ] <= ' 9' )) {
571- return true ;
572- }
573- return false ;
574- };
575565 // [a-z0-9]+(-[a-z0-9]+)*
576- auto is_identifier = [](const std::string &s) {
577- for (size_t i = 0 ; i < s.length (); i++) {
578- auto c = s[i];
579- if ((c >= ' a' && c <= ' z' ) || (c >= ' 0' && c <= ' 9' ) || (i > 0 && c == ' -' )) {
580- continue ;
581- }
582- return false ;
566+ for (size_t i = 0 ; i < name.length (); i++) {
567+ auto c = name[i];
568+ if ((c >= ' a' && c <= ' z' ) || (c >= ' 0' && c <= ' 9' ) || (i > 0 && c == ' -' )) {
569+ continue ;
583570 }
571+ return false ;
572+ }
573+ return true ;
574+ }
575+
576+ static bool vcpkg_identifier_reserved (const std::string &name) {
577+ // prn|aux|nul|con|lpt[1-9]|com[1-9]|core|default
578+ if (name == " prn" || name == " aux" || name == " nul" || name == " con" || name == " core" || name == " default" ) {
584579 return true ;
585- };
586- return is_identifier (name) && !is_reserved (name);
580+ }
581+ if (name.length () == 4 && (name.compare (0 , 3 , " lpt" ) == 0 || name.compare (0 , 3 , " com" ) == 0 ) && (name[3 ] >= ' 1' && name[3 ] <= ' 9' )) {
582+ return true ;
583+ }
584+ return false ;
587585}
588586
589587static std::string vcpkg_escape_identifier (const std::string &name) {
@@ -600,10 +598,12 @@ static std::string vcpkg_escape_identifier(const std::string &name) {
600598
601599 escaped += std::tolower (ch);
602600 }
603-
604601 if (!vcpkg_valid_identifier (escaped)) {
605602 throw std::runtime_error (" The escaped project name '" + escaped + " ' is not usable with [vcpkg]" );
606603 }
604+ if (vcpkg_identifier_reserved (escaped)) {
605+ throw std::runtime_error (" The escaped project name '" + escaped + " ' is a reserved name [vcpkg]" );
606+ }
607607 return escaped;
608608}
609609
@@ -847,11 +847,17 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
847847 const auto &package = packages[i];
848848 const auto &features = package.features ;
849849 if (!vcpkg_valid_identifier (package.name )) {
850- throw std::runtime_error (" Invalid vcpkg package name '" + package.name + " '" );
850+ throw std::runtime_error (" Invalid vcpkg package name '" + package.name + " ', name is not valid" );
851+ }
852+ if (vcpkg_identifier_reserved (package.name )) {
853+ throw std::runtime_error (" Invalid vcpkg package name '" + package.name + " ', name is reserved" );
851854 }
852855 for (const auto &feature : features) {
853856 if (!vcpkg_valid_identifier (feature)) {
854- throw std::runtime_error (" Invalid vcpkg package feature '" + feature + " '" );
857+ throw std::runtime_error (" Invalid vcpkg package feature '" + feature + " ', name is not valid" );
858+ }
859+ if (vcpkg_identifier_reserved (feature)) {
860+ throw std::runtime_error (" Invalid vcpkg package feature '" + feature + " ', name is reserved" );
855861 }
856862 }
857863 if (features.empty ()) {
0 commit comments