Pārlūkot izejas kodu

Fix handling of relative ".." in haxe.io.Path.normalize (closes #3019). Also clean up temp vars.

Dan Korostelev 11 gadi atpakaļ
vecāks
revīzija
7fa564c799
2 mainītis faili ar 5 papildinājumiem un 8 dzēšanām
  1. 2 8
      std/haxe/io/Path.hx
  2. 3 0
      tests/unit/unitstd/haxe/io/Path.unit.hx

+ 2 - 8
std/haxe/io/Path.hx

@@ -215,15 +215,9 @@ class Path {
 		}
 
 		var target = [];
-		var src;
-		var parts;
-		var token;
 
-		src = path.split(slash);
-		for( i in 0...src.length ) {
-			token = src[i];
-
-			if(token == '..') {
+		for( token in path.split(slash) ) {
+			if(token == '..' && target.length > 0 && target[target.length-1] != "..") {
 				target.pop();
 			} else if(token != '.') {
 				target.push(token);

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

@@ -78,6 +78,9 @@ haxe.io.Path.normalize("/dir1/dir2/../../test.foo") == "/test.foo";
 haxe.io.Path.normalize("dir1/dir2/dir3/dir4/../../../dir5") == "dir1/dir5";
 haxe.io.Path.normalize("C:\\Windows\\..\\Users/Waneck on Windows///.haxelib") == "C:/Users/Waneck on Windows/.haxelib";
 haxe.io.Path.normalize("http://haxe.org/downloads") == "http://haxe.org/downloads";
+haxe.io.Path.normalize("../mydir") == "../mydir";
+haxe.io.Path.normalize("../../mydir") == "../../mydir";
+haxe.io.Path.normalize("dir1/.././../mydir/..") == "..";
 
 // join
 haxe.io.Path.join(["dir1/dir2", "dir3/dir4"]) == "dir1/dir2/dir3/dir4";