Not allowing / or spaces in file name prefix (#461)

This commit is contained in:
Dhanya Thattil 2022-05-18 12:37:44 +02:00 committed by GitHub
parent a4bd2f1be7
commit f3edd4dc56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -1244,6 +1244,9 @@ Result<std::string> Detector::getFileNamePrefix(Positions pos) const {
}
void Detector::setFileNamePrefix(const std::string &fname, Positions pos) {
if (fname.find_first_of("/ ") != std::string::npos) {
throw RuntimeError("Cannot set file name prefix with '/' or ' '");
}
pimpl->Parallel(&Module::setFileName, pos, fname);
}

View File

@ -572,6 +572,9 @@ TEST_CASE("fname", "[.cmd]") {
proxy.Call("fname", {"run"}, -1, PUT, oss);
REQUIRE(oss.str() == "fname run\n");
}
REQUIRE_THROWS(proxy.Call("fname", {"fdf/dfd"}, -1, PUT));
REQUIRE_THROWS(proxy.Call("fname", {"fdf dfd"}, -1, PUT));
for (int i = 0; i != det.size(); ++i) {
det.setFileNamePrefix(prev_val[i], {i});
}