From a86f25b3b4c737527539ee8533df4a250a6a7f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Thu, 4 Apr 2019 16:20:46 +0200 Subject: [PATCH 1/2] Fix range violation in makeFileInfo and add some unit tests. --- source/vibe/core/file.d | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/source/vibe/core/file.d b/source/vibe/core/file.d index 192a9c0..6117708 100644 --- a/source/vibe/core/file.d +++ b/source/vibe/core/file.d @@ -733,11 +733,13 @@ private FileInfo makeFileInfo(DirEntry ent) import std.algorithm.comparison : among; FileInfo ret; - if (!ent.name.length) return ret; - - auto fullname = ent.name[$-1].among('/', '\\') ? ent.name[0 .. $-1] : ent.name; - ret.name = baseName(fullname); - if (ret.name.length == 0) ret.name = fullname; + string fullname = ent.name; + if (ent.name.length) { + if (ent.name[$-1].among('/', '\\')) + fullname = ent.name[0 .. $-1]; + ret.name = baseName(fullname); + if (ret.name.length == 0) ret.name = fullname; + } try { ret.isFile = ent.isFile; @@ -755,7 +757,31 @@ private FileInfo makeFileInfo(DirEntry ent) import core.sys.windows.windows : FILE_ATTRIBUTE_HIDDEN; ret.hidden = (ent.attributes & FILE_ATTRIBUTE_HIDDEN) != 0; } - else ret.hidden = ret.name[0] == '.' && ret.name != "." && ret.name != ".."; + else ret.hidden = ret.name.length > 1 && ret.name[0] == '.' && ret.name != ".."; return ret; } + +version (Windows) {} else unittest { + void test(string name_in, string name_out, bool hidden) { + auto de = DirEntry(name_in); + assert(makeFileInfo(de).hidden == hidden); + assert(makeFileInfo(de).name == name_out); + } + + void testCreate(string name_in, string name_out, bool hidden) + { + if (name_in.endsWith("/")) + createDirectory(name_in); + else writeFileUTF8(NativePath(name_in), name_in); + scope (exit) removeFile(name_in); + test(name_in, name_out, hidden); + } + + test(".", ".", false); + test("..", "..", false); + testCreate(".test_foo", ".test_foo", true); + test("./", ".", false); + testCreate(".test_foo/", ".test_foo", true); + test("/", "", false); +} From 1ca950867a2b01c69de481cd76c2764f9baf5452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Thu, 4 Apr 2019 16:21:04 +0200 Subject: [PATCH 2/2] Fix typo. --- source/vibe/core/net.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/vibe/core/net.d b/source/vibe/core/net.d index 095e12d..2e3d309 100644 --- a/source/vibe/core/net.d +++ b/source/vibe/core/net.d @@ -621,7 +621,7 @@ mixin(tracer); Returns: If the read readiness can be determined immediately, it will be - returned as WaitForDataAsyncStatus.sataAvailable` or + returned as `WaitForDataAsyncStatus.dataAvailable` or `WaitForDataAsyncStatus.noModeData` and the callback will not be invoked. Otherwise `WaitForDataAsyncStatus.waiting` is returned and the callback will be invoked once the status can be