From 429d5dcb771af5d5953f6061cf53ed6164a54b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 7 Jul 2017 22:29:12 +0200 Subject: [PATCH] Fix GenericPath.parentPath. --- source/vibe/core/path.d | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/source/vibe/core/path.d b/source/vibe/core/path.d index 33fbeef..607d369 100644 --- a/source/vibe/core/path.d +++ b/source/vibe/core/path.d @@ -480,7 +480,7 @@ struct GenericPath(F) { auto b = Format.getBackNode(m_path); static const Exception e = new Exception("Path has no parent path"); if (b.length >= m_path.length) throw e; - return GenericPath.fromTrustedString(m_path[0 .. b.length]); + return GenericPath.fromTrustedString(m_path[0 .. $ - b.length]); } /** Removes any redundant path segments and replaces all separators by the @@ -722,6 +722,29 @@ unittest { assert(p.toString() == "/foo%2fbar/baz%2Fbam", p.toString); } +unittest { + assert(!PosixPath("").hasParentPath); + assert(!PosixPath("/").hasParentPath); + assert(!PosixPath("foo\\bar").hasParentPath); + assert(PosixPath("foo/bar").parentPath.toString() == "foo/"); + assert(PosixPath("./foo").parentPath.toString() == "./"); + assert(PosixPath("./foo").parentPath.toString() == "./"); + + assert(!WindowsPath("").hasParentPath); + assert(!WindowsPath("/").hasParentPath); + assert(WindowsPath("foo\\bar").parentPath.toString() == "foo\\"); + assert(WindowsPath("foo/bar").parentPath.toString() == "foo/"); + assert(WindowsPath("./foo").parentPath.toString() == "./"); + assert(WindowsPath("./foo").parentPath.toString() == "./"); + + assert(!InetPath("").hasParentPath); + assert(!InetPath("/").hasParentPath); + assert(InetPath("foo/bar").parentPath.toString() == "foo/"); + assert(InetPath("foo/bar%2Fbaz").parentPath.toString() == "foo/"); + assert(InetPath("./foo").parentPath.toString() == "./"); + assert(InetPath("./foo").parentPath.toString() == "./"); +} + /// Thrown when an invalid string representation of a path is detected. class PathValidationException : Exception { this(string text, string file = __FILE__, size_t line = cast(size_t)__LINE__, Throwable next = null)