Browse Source

Fix Path.normalize on paths starting with ".//" (Fixes #7548) (#7555)

Kevin Leung 6 years ago
parent
commit
cdc317b142
2 changed files with 9 additions and 0 deletions
  1. 4 0
      std/haxe/io/Path.hx
  2. 5 0
      tests/unit/src/unitstd/haxe/io/Path.unit.hx

+ 4 - 0
std/haxe/io/Path.hx

@@ -217,6 +217,10 @@ class Path {
 		for( token in path.split(slash) ) {
 			if(token == '..' && target.length > 0 && target[target.length-1] != "..") {
 				target.pop();
+			} else if(token == '') {
+				if(target.length > 0 || path.charCodeAt(0) == '/'.code) {
+					target.push(token);
+				}
 			} else if(token != '.') {
 				target.push(token);
 			}

+ 5 - 0
tests/unit/src/unitstd/haxe/io/Path.unit.hx

@@ -81,6 +81,11 @@ haxe.io.Path.normalize("http://haxe.org/downloads") == "http://haxe.org/download
 haxe.io.Path.normalize("../mydir") == "../mydir";
 haxe.io.Path.normalize("../../mydir") == "../../mydir";
 haxe.io.Path.normalize("dir1/.././../mydir/..") == "..";
+haxe.io.Path.normalize(".//dir1") == "dir1";
+haxe.io.Path.normalize(".//.//dir1") == "dir1";
+haxe.io.Path.normalize("././/dir1") == "dir1";
+haxe.io.Path.normalize("././dir1") == "dir1";
+haxe.io.Path.normalize("dir1/.//dir2") == "dir1/dir2";
 
 // join
 haxe.io.Path.join(["dir1/dir2", "dir3/dir4"]) == "dir1/dir2/dir3/dir4";