Open TeamPlatform1 opened 4 months ago
Hi,
If the TemplatesCustomNamer is instructed to create a filename starting with "//SomeHost/SomeDir..", the double (back)slash is removed in "removeRedundantDirectorySeparators", which makes it impossible to use UNC paths.
Please give a source code sample that we can use to test the problem.
And what backslash are you referring to? I only see forward slashes.
A snippet from our main.cpp:
::ApprovalTests::initializeApprovalTestsForGoogleTests();
APPROVAL_TESTS_REGISTER_MAIN_DIRECTORY
auto defaultNamer = ::ApprovalTests::Approvals::useAsDefaultNamer([]()
{
auto approvalFilesBaseDir = kernel::utilities::Environment::GetEnvironmentVariable(L"KERNEL_TEST_APPROVAL_FILES_BASE_DIR");
return std::make_shared<ApprovalTests::TemplatedCustomNamer>(
kernel::utilities::Convert::WStringToUTF8String(approvalFilesBaseDir) +
"/{RelativeTestSourceDirectory}/{TestFileName}.{TestCaseName}.{ApprovedOrReceived}.{FileExtension}"
);
});
In the environment variable I tried using something like "//server/base/path" and "\\server\base\path" (we're on windows).
In both cases the doubled (back)slash is eliminated in "removeRedundantDirectorySeparators". Looks like using a UNC path is currently impossible.
Thanks.
In case it helps in future, this is how to format code so it's readable here:
```cpp
<your code...>
```
I've made that edit in your post above.
Thank you for the code.
In both cases the doubled (back)slash is eliminated in
removeRedundantDirectorySeparators()
. Looks like using a UNC path is currently impossible.
Yes, I'm sure that's the problem.
I see that we have no explicit tests for that function.
The fix would be be to:
removeRedundantDirectorySeparators()
,
- add tests for the existing behaviour of
removeRedundantDirectorySeparators()
,
Likely something like this:
TEST_CASE("Path retains initial slashes in UNC paths")
{
const std::string start = R"(\\a\b\c.txt)";
Path path = Path(start);
CHECK("//a/b/c.txt" == path.toString("/"));
CHECK("\\\\a\\b\\c.txt" == path.toString("\\"));
}
If the TemplatesCustomNamer is instructed to create a filename starting with "//SomeHost/SomeDir..", the double (back)slash is removed in "removeRedundantDirectorySeparators", which makes it impossible to use UNC paths.