Skip to content

Commit

Permalink
Support empty path entries in Path (same as "." entries). See #410.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed May 14, 2014
1 parent 2199394 commit c752c83
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions source/vibe/inet/path.d
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ struct Path {
m_nodes = cast(immutable)splitPath(pathstr);
m_absolute = (pathstr.startsWith("/") || m_nodes.length > 0 && (m_nodes[0].toString().canFind(':') || m_nodes[0] == "\\"));
m_endsWithSlash = pathstr.endsWith("/");
foreach( e; m_nodes ) assert(e.toString().length > 0, "Empty path nodes not allowed: "~pathstr);
}

/// Constructs a path object from a list of PathEntry objects.
Expand Down Expand Up @@ -62,7 +61,7 @@ struct Path {
default:
newnodes ~= n;
break;
case ".": break;
case "", ".": break;
case "..":
enforce(!m_absolute || newnodes.length > 0, "Path goes below root node.");
if( newnodes.length > 0 && newnodes[$-1] != ".." ) newnodes = newnodes[0 .. $-1];
Expand Down Expand Up @@ -186,7 +185,7 @@ struct Path {
foreach (folder; rhs.m_nodes) {
switch (folder.toString()) {
default: ret.m_nodes = ret.m_nodes ~ folder; break;
case ".": break;
case "", ".": break;
case "..":
enforce(!ret.absolute || ret.m_nodes.length > 0, "Relative path goes below root node!");
if( ret.m_nodes.length > 0 && ret.m_nodes[$-1].toString() != ".." )
Expand Down Expand Up @@ -304,6 +303,14 @@ unittest
dotpathp.normalize();
assert(dotpathp.toString() == "/test2/x/y");
}

{
auto dotpath = "/test/..////test2//./x/y";
auto dotpathp = Path(dotpath);
assert(dotpathp.toString() == "/test/..////test2//./x/y");
dotpathp.normalize();
assert(dotpathp.toString() == "/test2/x/y");
}

{
auto parentpath = "/path/to/parent";
Expand Down Expand Up @@ -392,12 +399,10 @@ PathEntry[] splitPath(string path)
// read and return the elements
foreach( i, char ch; path )
if( ch == '\\' || ch == '/' ){
enforce(i - startidx > 0, "Empty path entries not allowed.");
storage[eidx++] = PathEntry(path[startidx .. i]);
startidx = i+1;
}
storage[eidx++] = PathEntry(path[startidx .. $]);
enforce(path.length - startidx > 0, "Empty path entries not allowed.");
assert(eidx == nelements);
return storage;
}
Expand Down

0 comments on commit c752c83

Please sign in to comment.