diff options
author | dec05eba <dec05eba@protonmail.com> | 2017-12-31 09:13:32 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2017-12-31 09:29:38 +0100 |
commit | eda6a8e2c66380c773db32f720ef4b6a89f9b50a (patch) | |
tree | 6d8f5f9a6dd2d1923864f94d0df2db85d041d2d4 /src/Conf.cpp | |
parent | c849a30e7e9e2e7608376c9c538e1b45e623c805 (diff) |
Update new project template with user platform
Validate package name only contains safe characters.
TODO: Validate package name is allowed on windows, names such as NUL, AUX are not allowed
Diffstat (limited to 'src/Conf.cpp')
-rw-r--r-- | src/Conf.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/Conf.cpp b/src/Conf.cpp index 02e92fe..c487e28 100644 --- a/src/Conf.cpp +++ b/src/Conf.cpp @@ -394,6 +394,17 @@ namespace sibs return false; } + bool isProjectNameValid(const string &projectName) + { + for(int i = 0; i < projectName.size(); ++i) + { + char c = projectName[i]; + if(!isalpha(c) && !isdigit(c) && c != '-' && c != '_') + return false; + } + return true; + } + bool SibsConfig::isDefined(const std::string &name) const { return defines.find(name) != defines.end(); @@ -480,6 +491,8 @@ namespace sibs packageName = string(value.asSingle().data, value.asSingle().size); else throw ParserException("Expected package.name to be a single value, was a list"); + + validatePackageName(); } else if(name.equals("type")) { @@ -710,6 +723,17 @@ namespace sibs if(platforms.empty()) throw ParserException("Missing required config package.platforms. If the package supports all platforms, add:\nplatforms = [\"any\"]\nto project.conf under [package]"); } + + void SibsConfig::validatePackageName() const + { + if(!isProjectNameValid(packageName)) + { + string errMsg = "Invalid package name: "; + errMsg += packageName; + errMsg += ". Package name can only contain alphanumerical characters, dash (-) or underscore (_)"; + throw ParserException(errMsg); + } + } void SibsTestConfig::processObject(StringView name) { |