Skip to content

Commit 0a17495

Browse files
committed
Treat root path in normalizeCLIPathForVFS as case insensitive on Windows
1 parent 2f0ccb2 commit 0a17495

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

libsolidity/interface/FileReader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ boost::filesystem::path FileReader::normalizeCLIPathForVFS(
269269
if (!isUNCPath(normalizedPath))
270270
{
271271
boost::filesystem::path workingDirRootPath = canonicalWorkDir.root_path();
272-
if (normalizedRootPath == workingDirRootPath)
272+
// Ignore drive letter case on Windows (C:\ <=> c:\).
273+
if (boost::filesystem::equivalent(normalizedRootPath, workingDirRootPath))
273274
normalizedRootPath = "/";
274275
}
275276

test/libsolidity/interface/FileReader.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <test/TemporaryDirectory.h>
2626
#include <test/libsolidity/util/SoltestErrors.h>
2727

28+
#include <boost/algorithm/string.hpp>
2829
#include <boost/filesystem.hpp>
2930
#include <boost/test/unit_test.hpp>
3031

@@ -192,8 +193,8 @@ BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_root_name_only)
192193

193194
#if defined(_WIN32)
194195
boost::filesystem::path driveLetter = boost::filesystem::current_path().root_name();
195-
solAssert(!driveLetter.empty(), "");
196-
solAssert(driveLetter.is_relative(), "");
196+
soltestAssert(!driveLetter.empty(), "");
197+
soltestAssert(driveLetter.is_relative(), "");
197198

198199
BOOST_CHECK_EQUAL(FileReader::normalizeCLIPathForVFS(driveLetter, resolveSymlinks), expectedWorkDir);
199200
#endif
@@ -212,13 +213,32 @@ BOOST_AUTO_TEST_CASE(normalizeCLIPathForVFS_stripping_root_name)
212213

213214
for (SymlinkResolution resolveSymlinks: {SymlinkResolution::Enabled, SymlinkResolution::Disabled})
214215
{
216+
boost::filesystem::path workDir = boost::filesystem::current_path();
217+
215218
boost::filesystem::path normalizedPath = FileReader::normalizeCLIPathForVFS(
216-
boost::filesystem::current_path(),
219+
workDir,
217220
resolveSymlinks
218221
);
219-
BOOST_CHECK_EQUAL(normalizedPath, "/" / boost::filesystem::current_path().relative_path());
222+
BOOST_CHECK_EQUAL(normalizedPath, "/" / workDir.relative_path());
220223
BOOST_TEST(normalizedPath.root_name().empty());
221224
BOOST_CHECK_EQUAL(normalizedPath.root_directory(), "/");
225+
226+
#if defined(_WIN32)
227+
string root = workDir.root_path().string();
228+
soltestAssert(root.length() == 3 && root[1] == ':' && root[2] == '\\', "");
229+
230+
for (auto convert: {boost::to_lower_copy<string>, boost::to_upper_copy<string>})
231+
{
232+
boost::filesystem::path workDirWin = convert(root, locale()) / workDir.relative_path();
233+
normalizedPath = FileReader::normalizeCLIPathForVFS(
234+
workDirWin,
235+
resolveSymlinks
236+
);
237+
BOOST_CHECK_EQUAL(normalizedPath, "/" / workDir.relative_path());
238+
BOOST_TEST(normalizedPath.root_name().empty());
239+
BOOST_CHECK_EQUAL(normalizedPath.root_directory(), "/");
240+
}
241+
#endif
222242
}
223243
}
224244

0 commit comments

Comments
 (0)