◐ Shell
clean mode source ↗

fs,win: fix readdir for named pipe · nodejs/node@0331b3f

@@ -1887,8 +1887,29 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {

1887188718881888

BufferValue path(isolate, args[0]);

18891889

CHECK_NOT_NULL(*path);

1890+

#ifdef _WIN32

1891+

// On Windows, some API functions accept paths with trailing slashes,

1892+

// while others do not. This code checks if the input path ends with

1893+

// a slash (either '/' or '\\') and, if so, ensures that the processed

1894+

// path also ends with a trailing backslash ('\\').

1895+

bool slashCheck = false;

1896+

if (path.ToStringView().ends_with("/") ||

1897+

path.ToStringView().ends_with("\\")) {

1898+

slashCheck = true;

1899+

}

1900+

#endif

1901+18901902

ToNamespacedPath(env, &path);

189119031904+

#ifdef _WIN32

1905+

if (slashCheck) {

1906+

size_t new_length = path.length() + 1;

1907+

path.AllocateSufficientStorage(new_length + 1);

1908+

path.SetLengthAndZeroTerminate(new_length);

1909+

path.out()[new_length - 1] = '\\';

1910+

}

1911+

#endif

1912+18921913

const enum encoding encoding = ParseEncoding(isolate, args[1], UTF8);

1893191418941915

bool with_types = args[2]->IsTrue();