From 8a57b6aeb2ceea6e60d0a39c05c3e93a66414499 Mon Sep 17 00:00:00 2001 From: Lutger Blijdestijn Date: Fri, 24 May 2013 09:43:13 +0200 Subject: [PATCH 1/2] fixes unc path error --- source/dub/internal/vibecompat/inet/path.d | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/dub/internal/vibecompat/inet/path.d b/source/dub/internal/vibecompat/inet/path.d index 4a662f95b..e12cf3f0c 100644 --- a/source/dub/internal/vibecompat/inet/path.d +++ b/source/dub/internal/vibecompat/inet/path.d @@ -273,7 +273,11 @@ string joinPath(string basepath, string subpath) /// Splits up a path string into its elements/folders PathEntry[] splitPath(string path) { - if( path.startsWith("/") || path.startsWith("\\") ) path = path[1 .. $]; + if( path.startsWith("/") || path.startsWith("\\") ) + { + if( path.startsWith("\\") ) path = path[2 .. $]; + else path = path[1 .. $]; + } if( path.empty ) return null; if( path.endsWith("/") || path.endsWith("\\") ) path = path[0 .. $-1]; From 04232aa57de6998248fc5ff5e5cad3ae76d11d89 Mon Sep 17 00:00:00 2001 From: Lutger Blijdestijn Date: Sat, 25 May 2013 13:59:12 +0200 Subject: [PATCH 2/2] fixes support for unc path --- source/dub/internal/vibecompat/inet/path.d | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/source/dub/internal/vibecompat/inet/path.d b/source/dub/internal/vibecompat/inet/path.d index e12cf3f0c..3d87db0d0 100644 --- a/source/dub/internal/vibecompat/inet/path.d +++ b/source/dub/internal/vibecompat/inet/path.d @@ -240,7 +240,7 @@ struct PathEntry { this(string str) { - assert(str.countUntil('/') < 0 && str.countUntil('\\') < 0); + assert(str.countUntil('/') < 0 && (str.countUntil('\\') < 0 || str.length == 1)); m_name = str; } @@ -273,11 +273,7 @@ string joinPath(string basepath, string subpath) /// Splits up a path string into its elements/folders PathEntry[] splitPath(string path) { - if( path.startsWith("/") || path.startsWith("\\") ) - { - if( path.startsWith("\\") ) path = path[2 .. $]; - else path = path[1 .. $]; - } + if( path.startsWith("/") || path.startsWith("\\") ) path = path[1 .. $]; if( path.empty ) return null; if( path.endsWith("/") || path.endsWith("\\") ) path = path[0 .. $-1]; @@ -287,13 +283,20 @@ PathEntry[] splitPath(string path) if( ch == '\\' || ch == '/' ) nelements++; nelements++; - + // reserve space for the elements auto elements = new PathEntry[nelements]; + size_t eidx = 0; + + // detect UNC path + if(path.startsWith("\\")) + { + elements[eidx++] = PathEntry(path[0 .. 1]); + path = path[1 .. $]; + } // read and return the elements size_t startidx = 0; - size_t eidx = 0; foreach( i, char ch; path ) if( ch == '\\' || ch == '/' ){ enforce(i - startidx > 0, "Empty path entries not allowed."); @@ -305,3 +308,9 @@ PathEntry[] splitPath(string path) assert(eidx == nelements); return elements; } + +unittest +{ + auto unc = "\\\\server\\share\\path"; + assert(Path(unc).toNativeString() == unc); +} \ No newline at end of file