From 9674d44e5827e3229e5b720b54de38bb4a1157b5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Thu, 13 Nov 1997 14:13:29 -0800
Subject: [PATCH] combine_path() fixed

Rev: src/builtin_functions.c:1.57
Rev: src/testsuite.in:1.61
---
 src/builtin_functions.c | 16 ++++++++--------
 src/testsuite.in        |  3 ++-
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/builtin_functions.c b/src/builtin_functions.c
index 624c3bc478..45e659cbf9 100644
--- a/src/builtin_functions.c
+++ b/src/builtin_functions.c
@@ -4,7 +4,7 @@
 ||| See the files COPYING and DISCLAIMER for more information.
 \*/
 #include "global.h"
-RCSID("$Id: builtin_functions.c,v 1.56 1997/11/08 01:34:36 hubbe Exp $");
+RCSID("$Id: builtin_functions.c,v 1.57 1997/11/13 22:13:28 hubbe Exp $");
 #include "interpret.h"
 #include "svalue.h"
 #include "pike_macros.h"
@@ -426,7 +426,7 @@ static char *combine_path(char *cwd,char *file)
   {
     if(*from == '/')
     {
-      while(from[1] == '/') from++;
+      while(to>ret && to[-1]=='/') to--;
       if(from[1] == '.')
       {
 	switch(from[2])
@@ -438,17 +438,13 @@ static char *combine_path(char *cwd,char *file)
 	    while(--tmp>=ret)
 	      if(*tmp == '/')
 		break;
+	    tmp++;
 
-	    if(tmp[1]=='.' && tmp[2]=='.' && (tmp[3]=='/' || !tmp[3]))
+	    if(tmp[0]=='.' && tmp[1]=='.' && (tmp[2]=='/' || !tmp[2]))
 	      break;
 	    
 	    from+=3;
 	    to=tmp;
-	    if(to<ret)
-	    {
-	      to++;
-	      if(*from) from++;
-	    }
 	    continue;
 	  }
 	  break;
@@ -463,6 +459,10 @@ static char *combine_path(char *cwd,char *file)
     from++;
     to++;
   }
+
+  if(*cwd && from[-1]!='/' && *ret && ret[-1]=='/')
+    *--to=0;
+
   if(!*ret)
   {
     if(*cwd=='/')
diff --git a/src/testsuite.in b/src/testsuite.in
index 97ca99ca3e..e80ab265a4 100644
--- a/src/testsuite.in
+++ b/src/testsuite.in
@@ -1,4 +1,4 @@
-test_true([["$Id: testsuite.in,v 1.60 1997/10/19 22:13:33 hubbe Exp $"]])
+test_true([["$Id: testsuite.in,v 1.61 1997/11/13 22:13:29 hubbe Exp $"]])
 test_eq(1e1,10.0)
 test_eq(1E1,10.0)
 test_eq(1e+1,10.0)
@@ -1512,6 +1512,7 @@ test_eq([[combine_path("/","/foo/././/bar/gazonk/../../../..")]],"/")
 test_eq([[combine_path("/","..")]],"/")
 test_eq([[combine_path("./","..")]],"..")
 test_eq([[combine_path("./.","..")]],"..")
+test_eq([[combine_path("/","../../foo")]],"/foo")
 test_eq([[combine_path("./foobar/.","..")]],".")
 
 // - compile_file
-- 
GitLab