Skip to content

Commit bfbdf75

Browse files
committed
Do not extend an already extended path.
1 parent 426d23b commit bfbdf75

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/unicode/utf8_everywhere/paths.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,14 @@ std::filesystem::path extended_path(const std::filesystem::path& path) NOEXCEPT
140140
// However this includes "considered relative" paths (with ".." segments).
141141
// That is of no consequence here because those will also be converted.
142142
// MAX_PATH includes the terminator, so a path of that length requires it.
143+
// An already extended path (e.g. by a shell) is not extended again.
143144
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
145+
constexpr std::wstring_view prefix{ L"\\\\?\\" };
144146
const auto full = qualified_path(path).wstring();
145-
return { (full.length() >= MAX_PATH) ? L"\\\\?\\" + full : full };
147+
if (full.starts_with(prefix) || full.length() < MAX_PATH)
148+
return { full };
149+
150+
return { std::wstring{ prefix } + full };
146151
BC_POP_WARNING()
147152
}
148153

test/unicode/utf8_everywhere/paths.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ BOOST_AUTO_TEST_CASE(paths__extended_path__maximum__extended)
193193
BOOST_REQUIRE_EQUAL(extended_path({ test_maximum }), test_maximum_extended);
194194
}
195195

196+
BOOST_AUTO_TEST_CASE(paths__extended_path__extended__unchanged)
197+
{
198+
BOOST_REQUIRE_EQUAL(extended_path(test_extended), test_extended);
199+
BOOST_REQUIRE_EQUAL(extended_path(test_maximum_extended), test_maximum_extended);
200+
}
201+
196202
BOOST_AUTO_TEST_SUITE_END()
197203

198204
BC_POP_WARNING()

0 commit comments

Comments
 (0)