commit 668b3bdf762eb3931e7408af05f9688b9337d083
parent a57bcb75f6192b377df599013e8380f91d5e1025
Author: cfillion <cfillion@users.noreply.github.com>
Date: Wed, 3 Aug 2016 04:27:50 -0400
package: ensure package names do not contain slashes
Diffstat:
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/src/package.cpp b/src/package.cpp
@@ -65,6 +65,8 @@ Package::Package(const Type type, const string &name, const Category *cat)
{
if(m_name.empty())
throw reapack_error("empty package name");
+ else if(m_name.find_first_of("/\\") != string::npos)
+ throw reapack_error(format("invalid package name '%1%'") % m_name);
}
Package::~Package()
diff --git a/test/package.cpp b/test/package.cpp
@@ -55,13 +55,35 @@ TEST_CASE("package type to string", M) {
REQUIRE("Unknown" == Package::displayType(static_cast<Package::Type>(-1)));
}
-TEST_CASE("empty package name", M) {
- try {
- Package pack(Package::ScriptType, string());
- FAIL();
+TEST_CASE("invalid package name", M) {
+ SECTION("empty") {
+ try {
+ Package pack(Package::ScriptType, string());
+ FAIL();
+ }
+ catch(const reapack_error &e) {
+ REQUIRE(string(e.what()) == "empty package name");
+ }
}
- catch(const reapack_error &e) {
- REQUIRE(string(e.what()) == "empty package name");
+
+ SECTION("slash") {
+ try {
+ Package pack(Package::ScriptType, "hello/world");
+ FAIL();
+ }
+ catch(const reapack_error &e) {
+ REQUIRE(string(e.what()) == "invalid package name 'hello/world'");
+ }
+ }
+
+ SECTION("backslash") {
+ try {
+ Package pack(Package::ScriptType, "hello\\world");
+ FAIL();
+ }
+ catch(const reapack_error &e) {
+ REQUIRE(string(e.what()) == "invalid package name 'hello\\world'");
+ }
}
}