From 6bf1913a096fd85c63dc1e11c5c53ae087facf98 Mon Sep 17 00:00:00 2001 From: Roza Date: Thu, 17 Dec 2020 15:47:18 -0500 Subject: [PATCH] Always use correct path separator when normalizing --- src/filesystem/filesystemImpl.cpp | 20 +++++++++++++++----- src/filesystem/filesystemImplApple.mm | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/filesystem/filesystemImpl.cpp b/src/filesystem/filesystemImpl.cpp index bafc34fd..83c7d2ee 100644 --- a/src/filesystem/filesystemImpl.cpp +++ b/src/filesystem/filesystemImpl.cpp @@ -74,13 +74,23 @@ std::string filesystemImpl::normalizePath(const char *path, bool preferred, bool stdPath.lexically_normal(); std::string ret(stdPath); + for (int i = 0; i < ret.length(); i++) { + char sep; + char sep_alt; #ifdef __WINDOWS__ - if (!preferred) { - for (int i = 0; i < ret.length(); i++) { - if (ret[i] == '\\') - ret[i] = '/'; + if (!preferred) { + sep = '\\'; + sep_alt = '/'; } - } + else #endif + { + sep = '/'; + sep_alt = '\\'; + } + + if (ret[i] == sep_alt) + ret[i] = sep; + } return ret; } diff --git a/src/filesystem/filesystemImplApple.mm b/src/filesystem/filesystemImplApple.mm index 3007e955..284f13ff 100644 --- a/src/filesystem/filesystemImplApple.mm +++ b/src/filesystem/filesystemImplApple.mm @@ -45,6 +45,7 @@ std::string filesystemImpl::normalizePath(const char *path, bool preferred, bool if (!absolute) { nspath = [nspath stringByReplacingOccurrencesOfString:pwd withString:@""]; } + nspath = [nspath stringByReplacingOccurrencesOfString:@"\\" withString:@"/"]; return std::string(NSTOPATH(nspath)); }