File tree Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -957,9 +957,9 @@ std::error_code detail::directory_iterator_construct(detail::DirIterState &IT,
957
957
return EC;
958
958
959
959
// Convert path to the format that Windows is happy with.
960
- if ( PathUTF16.size () > 0 &&
961
- !is_separator (PathUTF16[Path. size () - 1 ]) &&
962
- PathUTF16[Path. size () - 1 ] != L' :' ) {
960
+ size_t PathUTF16Len = PathUTF16.size ();
961
+ if (PathUTF16Len > 0 && !is_separator (PathUTF16[PathUTF16Len - 1 ]) &&
962
+ PathUTF16[PathUTF16Len - 1 ] != L' :' ) {
963
963
PathUTF16.push_back (L' \\ ' );
964
964
PathUTF16.push_back (L' *' );
965
965
} else {
Original file line number Diff line number Diff line change @@ -1149,6 +1149,39 @@ TEST_F(FileSystemTest, BrokenSymlinkDirectoryIteration) {
1149
1149
}
1150
1150
#endif
1151
1151
1152
+ #ifdef _WIN32
1153
+ TEST_F (FileSystemTest, UTF8ToUTF16DirectoryIteration) {
1154
+ // The Windows filesystem support uses UTF-16 and converts paths from the
1155
+ // input UTF-8. The UTF-16 equivalent of the input path can be shorter in
1156
+ // length.
1157
+
1158
+ // This test relies on TestDirectory not being so long such that MAX_PATH
1159
+ // would be exceeded (see widenPath). If that were the case, the UTF-16
1160
+ // path is likely to be longer than the input.
1161
+ const char *Pi = " \xcf\x80 " ; // UTF-8 lower case pi.
1162
+ std::string RootDir = (TestDirectory + " /" + Pi).str ();
1163
+
1164
+ // Create test directories.
1165
+ ASSERT_NO_ERROR (fs::create_directories (Twine (RootDir) + " /a" ));
1166
+ ASSERT_NO_ERROR (fs::create_directories (Twine (RootDir) + " /b" ));
1167
+
1168
+ std::error_code EC;
1169
+ unsigned Count = 0 ;
1170
+ for (fs::directory_iterator I (Twine (RootDir), EC), E; I != E;
1171
+ I.increment (EC)) {
1172
+ ASSERT_NO_ERROR (EC);
1173
+ StringRef DirName = path::filename (I->path ());
1174
+ EXPECT_TRUE (DirName == " a" || DirName == " b" );
1175
+ ++Count;
1176
+ }
1177
+ EXPECT_EQ (Count, 2U );
1178
+
1179
+ ASSERT_NO_ERROR (fs::remove (Twine (RootDir) + " /a" ));
1180
+ ASSERT_NO_ERROR (fs::remove (Twine (RootDir) + " /b" ));
1181
+ ASSERT_NO_ERROR (fs::remove (Twine (RootDir)));
1182
+ }
1183
+ #endif
1184
+
1152
1185
TEST_F (FileSystemTest, Remove) {
1153
1186
SmallString<64 > BaseDir;
1154
1187
SmallString<64 > Paths[4 ];
You can’t perform that action at this time.
0 commit comments