diff --git a/src/builtin_functions.c b/src/builtin_functions.c index 1869f904f0f911ce8e1a2270dda707ad3515c41c..8a751063bef60214ca91061c4982172c081be13f 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.39 1997/08/26 23:24:45 grubba Exp $"); +RCSID("$Id: builtin_functions.c,v 1.40 1997/08/27 02:39:17 hubbe Exp $"); #include "interpret.h" #include "svalue.h" #include "pike_macros.h" @@ -410,6 +410,9 @@ static char *combine_path(char *cwd,char *file) } from=to=ret; + + /* Skip all leading "./" */ + while(from[0]=='.' && from[1]=='/') from+=2; while(( *to = *from )) { @@ -423,22 +426,26 @@ static char *combine_path(char *cwd,char *file) case '.': if(from[3] == '/' || from[3] == 0) { + char *tmp=to; + while(--tmp>=ret) + if(*tmp == '/') + break; + + if(tmp[1]=='.' && tmp[2]=='.' && (tmp[3]=='/' || !tmp[3])) + break; + from+=3; - if(to != ret) + to=tmp; + if(to<ret) { - for(--to;*to!='/' && to>ret;to--); + to++; + if(*from) from++; } - if(!*from && to==ret && *to=='/') to++; continue; } break; case 0: - if (to == ret) { - /* Special case, so we don't get an empty string */ - to++; - } - /* FALL_THROUGH */ case '/': from+=2; continue; @@ -448,6 +455,17 @@ static char *combine_path(char *cwd,char *file) from++; to++; } + if(!*ret) + { + if(*cwd=='/') + { + ret[0]='/'; + ret[1]=0; + }else{ + ret[0]='.'; + ret[1]=0; + } + } if(my_cwd) free(my_cwd); return ret; diff --git a/src/testsuite.in b/src/testsuite.in index accd80eaed7032a7a1e7482c5550c9e55c4a6c2a..ea44ae88210a9ee8ec7deed787f7faae42d0e30f 100644 --- a/src/testsuite.in +++ b/src/testsuite.in @@ -1,4 +1,4 @@ -test_true([["$Id: testsuite.in,v 1.46 1997/08/26 22:29:18 grubba Exp $"]]) +test_true([["$Id: testsuite.in,v 1.47 1997/08/27 02:39:18 hubbe Exp $"]]) test_eq(1e1,10.0) test_eq(1E1,10.0) test_eq(1e+1,10.0) @@ -1467,6 +1467,10 @@ test_eq([[combine_path("/","/foo//bar/gazonk/../..")]],"/foo") test_eq([[combine_path("/","/foo/bar/./gazonk/../../..")]],"/") test_eq([[combine_path("/","/foo/../bar//./gazonk/../..")]],"/") test_eq([[combine_path("/","/foo/././/bar/gazonk/../../../..")]],"/") +test_eq([[combine_path("/","..")]],"/") +test_eq([[combine_path("./","..")]],"..") +test_eq([[combine_path("./.","..")]],"..") +test_eq([[combine_path("./foobar/.","..")]],".") // - compile_file // FIXME: add tests for compile_file