From 01b11f060e656c00f875d05a8d4b283f524b0358 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 21 May 2018 18:06:39 +0300 Subject: Add package name validation to parse_package_name() function --- bpkg/manifest-utility.cxx | 18 +++++++++++++++--- bpkg/manifest-utility.hxx | 3 ++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bpkg/manifest-utility.cxx b/bpkg/manifest-utility.cxx index 634f522..defa675 100644 --- a/bpkg/manifest-utility.cxx +++ b/bpkg/manifest-utility.cxx @@ -45,10 +45,22 @@ namespace bpkg if (const char* p = traits::find (s, n, '/')) n = static_cast (p - s); - if (n == 0) - fail << "empty package name in '" << s << "'"; + string nm (s, n); - return string (s, n); + // The package name may be a part of some compound argument. So while the + // invalid package name would likely result in the operation failure, the + // validating can ease the troubleshooting. + // + try + { + validate_package_name (nm); + } + catch (const invalid_argument& e) + { + fail << "invalid package name in '" << s << "': " << e; + } + + return nm; } version diff --git a/bpkg/manifest-utility.hxx b/bpkg/manifest-utility.hxx index 5e42b84..c22746b 100644 --- a/bpkg/manifest-utility.hxx +++ b/bpkg/manifest-utility.hxx @@ -31,7 +31,8 @@ namespace bpkg package_scheme parse_package_scheme (const char*&); - // Extract name and version components from [/]. + // Extract and validate the package name and version components from + // [/]. // string parse_package_name (const char*); -- cgit v1.1