From 2390d945d5cbd078eb7b8f0f3bd6697a9597430d Mon Sep 17 00:00:00 2001 From: John Turner <7strbass@gmail.com> Date: Thu, 28 Sep 2023 08:59:54 -0400 Subject: [PATCH] --properly handle multiple sequential ellipses includes test. --- src/esp/io/Io.cpp | 6 +++--- src/tests/IOTest.cpp | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/esp/io/Io.cpp b/src/esp/io/Io.cpp index 45b4e8fd51..f37baf8f11 100644 --- a/src/esp/io/Io.cpp +++ b/src/esp/io/Io.cpp @@ -41,9 +41,9 @@ std::string normalizePath(const std::string& srcPath) { // Get paths leading up to ellipsis-cancelled path auto prefixString = srcPath.substr(0, prevLoc); // recurses to get subsequent ellipses. - auto filteredPath = Cr::Utility::formatString("{}/{}", prefixString, - normalizePath(suffixString)); - return filteredPath; + auto filteredPath = + Cr::Utility::formatString("{}/{}", prefixString, suffixString); + return normalizePath(filteredPath); } // normalizePath std::vector globDirs(const std::string& pattern) { diff --git a/src/tests/IOTest.cpp b/src/tests/IOTest.cpp index 6b7a21c46d..0cdd4d3e08 100644 --- a/src/tests/IOTest.cpp +++ b/src/tests/IOTest.cpp @@ -108,6 +108,7 @@ void IOTest::testEllipsisFilter() { testPath1 = "/test/path/DELETE/../to/test/removal.txt"; res = esp::io::normalizePath(testPath1); CORRADE_COMPARE(res, "/test/path/to/test/removal.txt"); + testPath1 = "/test/path/DELETE/../to/DELETE/../test/DELETE/../multiple/removal.txt"; res = esp::io::normalizePath(testPath1); @@ -122,6 +123,12 @@ void IOTest::testEllipsisFilter() { res = esp::io::normalizePath(testPath1); CORRADE_COMPARE(res, "test/path/to/test/multiple/removal.txt"); + testPath1 = + "/test/path/DELETE/DELETE2/DELETE3/../../../to/DELETE/DELETE2/../../test/" + "DELETE/../consecutive/removal.txt"; + res = esp::io::normalizePath(testPath1); + CORRADE_COMPARE(res, "/test/path/to/test/consecutive/removal.txt"); + // ignore intitial ellipsis testPath1 = "/../test/path/DELETE/../to/test/initial/ignore.txt"; res = esp::io::normalizePath(testPath1);