From f3edd4dc56b4813817b0c4941cbdfd2fd7de3fce Mon Sep 17 00:00:00 2001 From: Dhanya Thattil <33750417+thattil@users.noreply.github.com> Date: Wed, 18 May 2022 12:37:44 +0200 Subject: [PATCH] Not allowing / or spaces in file name prefix (#461) --- slsDetectorSoftware/src/Detector.cpp | 3 +++ slsDetectorSoftware/tests/test-CmdProxy-rx.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 19db54e9a..80b3e3fb3 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1244,6 +1244,9 @@ Result 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); } diff --git a/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp b/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp index 627bbe4d1..34d433591 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp @@ -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}); }