diff --git a/test/libsolutil/CommonIO.cpp b/test/libsolutil/CommonIO.cpp index d31c9a560..f43ee6534 100644 --- a/test/libsolutil/CommonIO.cpp +++ b/test/libsolutil/CommonIO.cpp @@ -25,12 +25,16 @@ #include #include +#include #include #include +#include #include #include +#include +using namespace std::string_literals; using namespace solidity::test; #define TEST_CASE_NAME (boost::unit_test::framework::current_test_case().p_name) @@ -38,6 +42,22 @@ using namespace solidity::test; namespace solidity::util::test { +namespace +{ + +/// Joins two paths in a way that matches the way used by util::absolutePath() to +/// combine the import with the reference. Not generic - only does enough to handle example +/// paths used in this test suite. +std::string absolutePathJoin(std::string const& _parent, std::string const& _suffix) +{ + if (!_parent.empty() && _parent != "/" && !_suffix.empty()) + return _parent + "/" + _suffix; + + return _parent + _suffix; +} + +} + BOOST_AUTO_TEST_SUITE(CommonIOTest) BOOST_AUTO_TEST_CASE(readFileAsString_regular_file) @@ -98,6 +118,426 @@ BOOST_AUTO_TEST_CASE(readBytes_past_end) BOOST_CHECK_EQUAL(readBytes(inputStream, 20), ""); } +BOOST_DATA_TEST_CASE( + absolutePath_direct_import, + boost::unit_test::data::make(std::vector{ + "", + "/", + "x", + "/x", + "x/", + "/x/", + "x/y", + "/x/y", + "x/y/", + "/x/y/", + ".", + "..", + "./../.../../." + }), + reference +) +{ + // absolutePath() should have no effect on a direct import, regardless of what the source + // unit name of the importing module is. + + BOOST_TEST(absolutePath("", reference) == ""); + BOOST_TEST(absolutePath("/", reference) == "/"); + BOOST_TEST(absolutePath("//", reference) == "//"); + BOOST_TEST(absolutePath("///", reference) == "///"); + + BOOST_TEST(absolutePath("\\", reference) == "\\"); + BOOST_TEST(absolutePath("\\\\", reference) == "\\\\"); + BOOST_TEST(absolutePath("\\\\\\", reference) == "\\\\\\"); + + BOOST_TEST(absolutePath(".\\", reference) == ".\\"); + BOOST_TEST(absolutePath(".\\\\", reference) == ".\\\\"); + BOOST_TEST(absolutePath(".\\\\\\", reference) == ".\\\\\\"); + + BOOST_TEST(absolutePath("..\\", reference) == "..\\"); + BOOST_TEST(absolutePath("..\\\\", reference) == "..\\\\"); + BOOST_TEST(absolutePath("..\\\\\\", reference) == "..\\\\\\"); + + BOOST_TEST(absolutePath("...", reference) == "..."); + BOOST_TEST(absolutePath("....", reference) == "...."); + BOOST_TEST(absolutePath("...a", reference) == "...a"); + + BOOST_TEST(absolutePath("/./", reference) == "/./"); + BOOST_TEST(absolutePath("/././", reference) == "/././"); + BOOST_TEST(absolutePath("/../", reference) == "/../"); + BOOST_TEST(absolutePath("/../../", reference) == "/../../"); + BOOST_TEST(absolutePath("//..//..//", reference) == "//..//..//"); + BOOST_TEST(absolutePath("///..///..///", reference) == "///..///..///"); + + BOOST_TEST(absolutePath("@", reference) == "@"); + BOOST_TEST(absolutePath(":", reference) == ":"); + BOOST_TEST(absolutePath("|", reference) == "|"); + BOOST_TEST(absolutePath("<>", reference) == "<>"); + BOOST_TEST(absolutePath("123", reference) == "123"); + BOOST_TEST(absolutePath("https://example.com", reference) == "https://example.com"); + + BOOST_TEST(absolutePath("a", reference) == "a"); + BOOST_TEST(absolutePath("a/", reference) == "a/"); + BOOST_TEST(absolutePath("/a", reference) == "/a"); + BOOST_TEST(absolutePath("/a/", reference) == "/a/"); + + BOOST_TEST(absolutePath("a/b", reference) == "a/b"); + BOOST_TEST(absolutePath("a/b/", reference) == "a/b/"); + BOOST_TEST(absolutePath("/a/b", reference) == "/a/b"); + BOOST_TEST(absolutePath("/a/b/", reference) == "/a/b/"); + + BOOST_TEST(absolutePath("/.", reference) == "/."); + BOOST_TEST(absolutePath("a.", reference) == "a."); + BOOST_TEST(absolutePath("a/.", reference) == "a/."); + BOOST_TEST(absolutePath("/a/.", reference) == "/a/."); + BOOST_TEST(absolutePath("a/./", reference) == "a/./"); + BOOST_TEST(absolutePath("/a/./", reference) == "/a/./"); + + BOOST_TEST(absolutePath("/..", reference) == "/.."); + BOOST_TEST(absolutePath("a..", reference) == "a.."); + BOOST_TEST(absolutePath("a/..", reference) == "a/.."); + BOOST_TEST(absolutePath("/a/..", reference) == "/a/.."); + BOOST_TEST(absolutePath("a/../", reference) == "a/../"); + BOOST_TEST(absolutePath("/a/../", reference) == "/a/../"); + + BOOST_TEST(absolutePath("a//", reference) == "a//"); + BOOST_TEST(absolutePath("//a", reference) == "//a"); + BOOST_TEST(absolutePath("//a//", reference) == "//a//"); + + BOOST_TEST(absolutePath("a//b", reference) == "a//b"); + BOOST_TEST(absolutePath("a//b//", reference) == "a//b//"); + BOOST_TEST(absolutePath("//a//b", reference) == "//a//b"); + BOOST_TEST(absolutePath("//a//b//", reference) == "//a//b//"); + + BOOST_TEST(absolutePath("a\\b", reference) == "a\\b"); + BOOST_TEST(absolutePath("a\\b\\", reference) == "a\\b\\"); + BOOST_TEST(absolutePath("\\a\\b", reference) == "\\a\\b"); + BOOST_TEST(absolutePath("\\a\\b\\", reference) == "\\a\\b\\"); +} + +BOOST_DATA_TEST_CASE( + absolutePath_relative_import_no_backtracking_into_reference, + boost::unit_test::data::make(std::vector>{ + {"", ""}, + {"/", "/"}, + {"x", ""}, + {"/x", "/"}, + {"x/", "x"}, + {"/x/", "/x"}, + {"x/y", "x"}, + {"/x/y", "/x"}, + {"x/y/", "x/y"}, + {"/x/y/", "/x/y"}, + }), + reference, + parent +) +{ + BOOST_TEST(absolutePath(".", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath("./", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath(".//", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath(".///", reference) == absolutePathJoin(parent, "")); + + BOOST_TEST(absolutePath("./.", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath("././", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath(".//./", reference) == absolutePathJoin(parent, "")); + + BOOST_TEST(absolutePath("./a", reference) == absolutePathJoin(parent, "a")); + BOOST_TEST(absolutePath("./a/", reference) == absolutePathJoin(parent, "a")); + BOOST_TEST(absolutePath("./a/b", reference) == absolutePathJoin(parent, "a/b")); + BOOST_TEST(absolutePath("./a/b/", reference) == absolutePathJoin(parent, "a/b")); + + BOOST_TEST(absolutePath("./@", reference) == absolutePathJoin(parent, "@")); + BOOST_TEST(absolutePath("./:", reference) == absolutePathJoin(parent, ":")); + BOOST_TEST(absolutePath("./|", reference) == absolutePathJoin(parent, "|")); + BOOST_TEST(absolutePath("./<>", reference) == absolutePathJoin(parent, "<>")); + BOOST_TEST(absolutePath("./123", reference) == absolutePathJoin(parent, "123")); + BOOST_TEST(absolutePath("./https://example.com", reference) == absolutePathJoin(parent, "https:/example.com")); + + BOOST_TEST(absolutePath(".//a", reference) == absolutePathJoin(parent, "a")); + BOOST_TEST(absolutePath(".//a//", reference) == absolutePathJoin(parent, "a")); + BOOST_TEST(absolutePath(".//a//b", reference) == absolutePathJoin(parent, "a/b")); + BOOST_TEST(absolutePath(".//a//b//", reference) == absolutePathJoin(parent, "a/b")); + + BOOST_TEST(absolutePath("./a\\", reference) == absolutePathJoin(parent, "a\\")); + BOOST_TEST(absolutePath("./a\\b", reference) == absolutePathJoin(parent, "a\\b")); + BOOST_TEST(absolutePath("./a\\b\\", reference) == absolutePathJoin(parent, "a\\b\\")); + + BOOST_TEST(absolutePath("./a/.", reference) == absolutePathJoin(parent, "a")); + BOOST_TEST(absolutePath("./a/b/.", reference) == absolutePathJoin(parent, "a/b")); + BOOST_TEST(absolutePath("./a/./b/.", reference) == absolutePathJoin(parent, "a/b")); + + BOOST_TEST(absolutePath("./a/..", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath("./a/../", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath("./a/b/..", reference) == absolutePathJoin(parent, "a")); + BOOST_TEST(absolutePath("./a/b/../", reference) == absolutePathJoin(parent, "a")); + BOOST_TEST(absolutePath("./a/../b", reference) == absolutePathJoin(parent, "b")); + BOOST_TEST(absolutePath("./a/../b/", reference) == absolutePathJoin(parent, "b")); + BOOST_TEST(absolutePath("./a/../b/..", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath("./a/../b/../", reference) == absolutePathJoin(parent, "")); + + BOOST_TEST(absolutePath("./a\\..", reference) == absolutePathJoin(parent, "a\\..")); + BOOST_TEST(absolutePath("./a\\..\\", reference) == absolutePathJoin(parent, "a\\..\\")); + BOOST_TEST(absolutePath("./a\\b\\..", reference) == absolutePathJoin(parent, "a\\b\\..")); + BOOST_TEST(absolutePath("./a\\b\\..\\", reference) == absolutePathJoin(parent, "a\\b\\..\\")); + BOOST_TEST(absolutePath("./a\\..\\b", reference) == absolutePathJoin(parent, "a\\..\\b")); + BOOST_TEST(absolutePath("./a\\..\\b\\", reference) == absolutePathJoin(parent, "a\\..\\b\\")); + BOOST_TEST(absolutePath("./a\\..\\b\\..\\", reference) == absolutePathJoin(parent, "a\\..\\b\\..\\")); + + BOOST_TEST(absolutePath("./a\\../..", reference) == absolutePathJoin(parent, "")); +} + +BOOST_DATA_TEST_CASE( + absolutePath_relative_import_with_backtracking_1_level_into_reference, + boost::unit_test::data::make(std::vector>{ + {"", ""}, + {"/", ""}, + {"x", ""}, + {"/x", ""}, + {"x/", ""}, + {"/x/", "/"}, + {"x/y", ""}, + {"/x/y", "/"}, + {"x/y/", "x"}, + {"/x/y/", "/x"}, + }), + reference, + parent +) +{ + BOOST_TEST(absolutePath("..", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath("../", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath("..//", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath("..///", reference) == absolutePathJoin(parent, "")); + + BOOST_TEST(absolutePath("../a", reference) == absolutePathJoin(parent, "a")); + BOOST_TEST(absolutePath("../a/", reference) == absolutePathJoin(parent, "a")); + BOOST_TEST(absolutePath("../a/b", reference) == absolutePathJoin(parent, "a/b")); + BOOST_TEST(absolutePath("../a/b/", reference) == absolutePathJoin(parent, "a/b")); + + BOOST_TEST(absolutePath("../@", reference) == absolutePathJoin(parent, "@")); + BOOST_TEST(absolutePath("../:", reference) == absolutePathJoin(parent, ":")); + BOOST_TEST(absolutePath("../|", reference) == absolutePathJoin(parent, "|")); + BOOST_TEST(absolutePath("../<>", reference) == absolutePathJoin(parent, "<>")); + BOOST_TEST(absolutePath("../123", reference) == absolutePathJoin(parent, "123")); + BOOST_TEST(absolutePath("../https://example.com", reference) == absolutePathJoin(parent, "https:/example.com")); + + BOOST_TEST(absolutePath("../a/..", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath("../a/b/..", reference) == absolutePathJoin(parent, "a")); + BOOST_TEST(absolutePath("../a/b/../..", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath("../a/../b/..", reference) == absolutePathJoin(parent, "")); + + BOOST_TEST(absolutePath("./../a/..", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath("./../a/b/..", reference) == absolutePathJoin(parent, "a")); + BOOST_TEST(absolutePath("./../a/b/../..", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath("./../a/../b/..", reference) == absolutePathJoin(parent, "")); + + BOOST_TEST(absolutePath("./a/../..", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath("./a/b/../../..", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath("./a/../b/../..", reference) == absolutePathJoin(parent, "")); + BOOST_TEST(absolutePath("./a/../../b/..", reference) == absolutePathJoin(parent, "")); + + BOOST_TEST(absolutePath("./a/../../c", reference) == absolutePathJoin(parent, "c")); + BOOST_TEST(absolutePath("./a/b/../../../c", reference) == absolutePathJoin(parent, "c")); + BOOST_TEST(absolutePath("./a/../b/../../c", reference) == absolutePathJoin(parent, "c")); + BOOST_TEST(absolutePath("./a/../../b/../c/d", reference) == absolutePathJoin(parent, "c/d")); + + BOOST_TEST(absolutePath("..//a", reference) == absolutePathJoin(parent, "a")); + BOOST_TEST(absolutePath("..//a//", reference) == absolutePathJoin(parent, "a")); + BOOST_TEST(absolutePath(".//a//..//..//b", reference) == absolutePathJoin(parent, "b")); +} + +BOOST_AUTO_TEST_CASE(absolutePath_relative_import_with_backtracking_multiple_levels_level_into_reference) +{ + BOOST_TEST(absolutePath("..", "x/y/z/") == "x/y"); + BOOST_TEST(absolutePath("../..", "x/y/z/") == "x"); + BOOST_TEST(absolutePath("../../..", "x/y/z/") == ""); + BOOST_TEST(absolutePath("../../../..", "x/y/z/") == ""); + + BOOST_TEST(absolutePath("..", "/x/y/z/") == "/x/y"); + BOOST_TEST(absolutePath("../..", "/x/y/z/") == "/x"); + BOOST_TEST(absolutePath("../../..", "/x/y/z/") == "/"); + BOOST_TEST(absolutePath("../../../..", "/x/y/z/") == ""); + + BOOST_TEST(absolutePath("../../../../a", "x/y/z/") == "a"); + BOOST_TEST(absolutePath("../../../../a/..", "x/y/z/") == ""); + BOOST_TEST(absolutePath("../../../../a/../a", "x/y/z/") == "a"); + + BOOST_TEST(absolutePath("../.", "x/y/z/") == "x/y"); + BOOST_TEST(absolutePath(".././..", "x/y/z/") == "x"); + BOOST_TEST(absolutePath(".././.././..", "x/y/z/") == ""); + BOOST_TEST(absolutePath("./../././.././.././..", "x/y/z/") == ""); +} + +BOOST_AUTO_TEST_CASE(absolutePath_relative_import_and_relative_segments_in_reference) +{ + BOOST_TEST(absolutePath(".", "x/../y/./z/") == "x/../y/./z"); + BOOST_TEST(absolutePath("..", "x/../y/./z/") == "x/../y/."); + BOOST_TEST(absolutePath("../..", "x/../y/./z/") == "x/../y"); + BOOST_TEST(absolutePath("../../..", "x/../y/./z/") == "x/.."); + BOOST_TEST(absolutePath("../../../..", "x/../y/./z/") == "x"); + BOOST_TEST(absolutePath("../../../../..", "x/../y/./z/") == ""); + BOOST_TEST(absolutePath("../../../../../..", "x/../y/./z/") == ""); +} + +BOOST_AUTO_TEST_CASE(absolutePath_relative_import_and_consecutive_slashes_in_reference) +{ + BOOST_TEST(absolutePath(".", "/x/") == "/x"); + BOOST_TEST(absolutePath("..", "/x/") == "/"); + BOOST_TEST(absolutePath("../..", "/x/") == ""); + + BOOST_TEST(absolutePath(".", "//x//") == "//x//"); + BOOST_TEST(absolutePath("..", "//x//") == "//x"); + BOOST_TEST(absolutePath("../..", "//x//") == ""); + + BOOST_TEST(absolutePath(".", "///x///") == "///x"); + BOOST_TEST(absolutePath("..", "///x///") == "/"); + BOOST_TEST(absolutePath("../..", "///x///") == ""); +} + +BOOST_AUTO_TEST_CASE(absolutePath_relative_import_and_unnormalized_slashes_in_reference) +{ + BOOST_TEST(absolutePath(".", "//x//y\\z/\\//") == "//x//y\\z/\\"); + BOOST_TEST(absolutePath("..", "//x//y\\z/\\//") == "//x//y\\z"); + BOOST_TEST(absolutePath("../..", "//x//y\\z/\\//") == "//x/"); + BOOST_TEST(absolutePath("../../..", "//x//y\\z/\\//") == "//x"); + BOOST_TEST(absolutePath("../../../..", "//x//y\\z/\\//") == ""); +} + +BOOST_AUTO_TEST_CASE(sanitizePath_direct_import) +{ + BOOST_TEST(sanitizePath("") == ""); + BOOST_TEST(sanitizePath("/") == "/"); + BOOST_TEST(sanitizePath("//") == "//"); + BOOST_TEST(sanitizePath("///") == "///"); + + BOOST_TEST(sanitizePath("\\") == "\\"); + BOOST_TEST(sanitizePath("\\\\") == "\\\\"); + BOOST_TEST(sanitizePath("\\\\\\") == "\\\\\\"); + + BOOST_TEST(sanitizePath(".\\") == ".\\"); + BOOST_TEST(sanitizePath(".\\\\") == ".\\\\"); + BOOST_TEST(sanitizePath(".\\\\\\") == ".\\\\\\"); + + BOOST_TEST(sanitizePath("..\\") == "..\\"); + BOOST_TEST(sanitizePath("..\\\\") == "..\\\\"); + BOOST_TEST(sanitizePath("..\\\\\\") == "..\\\\\\"); + + BOOST_TEST(sanitizePath("...") == "..."); + BOOST_TEST(sanitizePath("....") == "...."); + BOOST_TEST(sanitizePath("...a") == "...a"); + + BOOST_TEST(sanitizePath("/./") == "/./"); + BOOST_TEST(sanitizePath("/././") == "/././"); + BOOST_TEST(sanitizePath("/../") == "/../"); + BOOST_TEST(sanitizePath("/../../") == "/../../"); + BOOST_TEST(sanitizePath("//..//..//") == "//..//..//"); + BOOST_TEST(sanitizePath("///..///..///") == "///..///..///"); + + BOOST_TEST(sanitizePath("@") == "@"); + BOOST_TEST(sanitizePath(":") == ":"); + BOOST_TEST(sanitizePath("|") == "|"); + BOOST_TEST(sanitizePath("<>") == "<>"); + BOOST_TEST(sanitizePath("123") == "123"); + BOOST_TEST(sanitizePath("https://example.com") == "https://example.com"); + + BOOST_TEST(sanitizePath("a") == "a"); + BOOST_TEST(sanitizePath("a/") == "a/"); + BOOST_TEST(sanitizePath("/a") == "/a"); + BOOST_TEST(sanitizePath("/a/") == "/a/"); + + BOOST_TEST(sanitizePath("a/b") == "a/b"); + BOOST_TEST(sanitizePath("a/b/") == "a/b/"); + BOOST_TEST(sanitizePath("/a/b") == "/a/b"); + BOOST_TEST(sanitizePath("/a/b/") == "/a/b/"); + + BOOST_TEST(sanitizePath("/.") == "/."); + BOOST_TEST(sanitizePath("a.") == "a."); + BOOST_TEST(sanitizePath("a/.") == "a/."); + BOOST_TEST(sanitizePath("/a/.") == "/a/."); + BOOST_TEST(sanitizePath("a/./") == "a/./"); + BOOST_TEST(sanitizePath("/a/./") == "/a/./"); + + BOOST_TEST(sanitizePath("/..") == "/.."); + BOOST_TEST(sanitizePath("a..") == "a.."); + BOOST_TEST(sanitizePath("a/..") == "a/.."); + BOOST_TEST(sanitizePath("/a/..") == "/a/.."); + BOOST_TEST(sanitizePath("a/../") == "a/../"); + BOOST_TEST(sanitizePath("/a/../") == "/a/../"); + + BOOST_TEST(sanitizePath("a//") == "a//"); + BOOST_TEST(sanitizePath("//a") == "//a"); + BOOST_TEST(sanitizePath("//a//") == "//a//"); + + BOOST_TEST(sanitizePath("a//b") == "a//b"); + BOOST_TEST(sanitizePath("a//b//") == "a//b//"); + BOOST_TEST(sanitizePath("//a//b") == "//a//b"); + BOOST_TEST(sanitizePath("//a//b//") == "//a//b//"); + + BOOST_TEST(sanitizePath("a\\b") == "a\\b"); + BOOST_TEST(sanitizePath("a\\b\\") == "a\\b\\"); + BOOST_TEST(sanitizePath("\\a\\b") == "\\a\\b"); + BOOST_TEST(sanitizePath("\\a\\b\\") == "\\a\\b\\"); +} + +BOOST_AUTO_TEST_CASE(sanitizePath_relative_import) +{ + BOOST_TEST(sanitizePath(".") == "."); + BOOST_TEST(sanitizePath("./") == "./"); + BOOST_TEST(sanitizePath(".//") == ".//"); + BOOST_TEST(sanitizePath(".///") == ".///"); + + BOOST_TEST(sanitizePath("./.") == "./."); + BOOST_TEST(sanitizePath("././") == "././"); + BOOST_TEST(sanitizePath(".//./") == ".//./"); + + BOOST_TEST(sanitizePath("./a") == "./a"); + BOOST_TEST(sanitizePath("./a/") == "./a/"); + BOOST_TEST(sanitizePath("./a/b") == "./a/b"); + BOOST_TEST(sanitizePath("./a/b/") == "./a/b/"); + + BOOST_TEST(sanitizePath("./@") == "./@"); + BOOST_TEST(sanitizePath("./:") == "./:"); + BOOST_TEST(sanitizePath("./|") == "./|"); + BOOST_TEST(sanitizePath("./<>") == "./<>"); + BOOST_TEST(sanitizePath("./123") == "./123"); + BOOST_TEST(sanitizePath("./https://example.com") == "./https://example.com"); + + BOOST_TEST(sanitizePath(".//a") == ".//a"); + BOOST_TEST(sanitizePath(".//a//") == ".//a//"); + BOOST_TEST(sanitizePath(".//a//b") == ".//a//b"); + BOOST_TEST(sanitizePath(".//a//b//") == ".//a//b//"); + + BOOST_TEST(sanitizePath("./a\\") == "./a\\"); + BOOST_TEST(sanitizePath("./a\\b") == "./a\\b"); + BOOST_TEST(sanitizePath("./a\\b\\") == "./a\\b\\"); + + BOOST_TEST(sanitizePath("./a/.") == "./a/."); + BOOST_TEST(sanitizePath("./a/b/.") == "./a/b/."); + BOOST_TEST(sanitizePath("./a/./b/.") == "./a/./b/."); + + BOOST_TEST(sanitizePath("./a/..") == "./a/.."); + BOOST_TEST(sanitizePath("./a/b/..") == "./a/b/.."); + BOOST_TEST(sanitizePath("./a/../b/../") == "./a/../b/../"); + + BOOST_TEST(sanitizePath("./a\\..\\b\\..\\") == "./a\\..\\b\\..\\"); + BOOST_TEST(sanitizePath("./a\\../..") == "./a\\../.."); + + BOOST_TEST(sanitizePath("..") == ".."); + BOOST_TEST(sanitizePath("../") == "../"); + BOOST_TEST(sanitizePath("..//") == "..//"); + BOOST_TEST(sanitizePath("..///") == "..///"); + + BOOST_TEST(sanitizePath("../..") == "../.."); + BOOST_TEST(sanitizePath("../../") == "../../"); + BOOST_TEST(sanitizePath("../../../") == "../../../"); + BOOST_TEST(sanitizePath("../../../../") == "../../../../"); + + BOOST_TEST(sanitizePath("../a") == "../a"); + BOOST_TEST(sanitizePath("../a/..") == "../a/.."); + BOOST_TEST(sanitizePath("./a/../../b/../c/d") == "./a/../../b/../c/d"); +} + BOOST_AUTO_TEST_SUITE_END() } // namespace solidity::util::test