From d549cfd66b1132d7835c600a5e91a4e16b9ef7d4 Mon Sep 17 00:00:00 2001 From: elsid Date: Tue, 16 Jan 2024 23:53:55 +0100 Subject: [PATCH] Check path for being normalized --- components/vfs/manager.cpp | 2 ++ components/vfs/pathutil.hpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/components/vfs/manager.cpp b/components/vfs/manager.cpp index d312ce9d84..1bf789402d 100644 --- a/components/vfs/manager.cpp +++ b/components/vfs/manager.cpp @@ -1,6 +1,7 @@ #include "manager.hpp" #include +#include #include #include @@ -44,6 +45,7 @@ namespace VFS Files::IStreamPtr Manager::getNormalized(std::string_view normalizedName) const { + assert(Path::isNormalized(normalizedName)); const auto found = mIndex.find(normalizedName); if (found == mIndex.end()) throw std::runtime_error("Resource '" + std::string(normalizedName) + "' not found"); diff --git a/components/vfs/pathutil.hpp b/components/vfs/pathutil.hpp index 9bcc263842..0856bfffa2 100644 --- a/components/vfs/pathutil.hpp +++ b/components/vfs/pathutil.hpp @@ -15,6 +15,11 @@ namespace VFS::Path return c == '\\' ? '/' : Misc::StringUtils::toLower(c); } + inline constexpr bool isNormalized(std::string_view name) + { + return std::all_of(name.begin(), name.end(), [](char v) { return v == normalize(v); }); + } + inline void normalizeFilenameInPlace(std::string& name) { std::transform(name.begin(), name.end(), name.begin(), normalize);