Branch: Tag:

2018-10-22

2018-10-22 14:38:41 by Henrik Grubbström (Grubba) <grubba@grubba.org>

combine_path: Fixed corner case (take 2).

The previous "fix" broke handling of paths starting with "./" in
cases other than "./../".

Fixes PIKE-137 (#8137) some more.

180: Inside #if defined(AMIGAOS_COMBINE_PATH)
   continue;    }   #else /* !AMIGAOS_COMBINE_PATH */ +  do { +  /* Remove sequences of ending slashes and single dots +  * from the result path. +  */    while(s->s->len && IS_SEP(LAST_PUSHED()))    s->s->len--; -  +  if (LAST_PUSHED() == '.') { +  if (s->s->len == 1) { +  /* Result path started with "./". */ +  s->s->len = 0; +  break; +  } else if (IS_SEP(index_shared_string(s->s, s->s->len-2))) { +  /* Result path ended with "/./". */ +  s->s->len -= 2; +  continue; +  } +  } +  /* Restore a single slash as directory separator. */    PUSH('/'); -  +  break; +  } while (1);    if(from<len && INDEX_PCHARP(path, from) == '.')    {    int c3;
198:    {    case '.':    c3=INDEX_PCHARP(path, from+2); -  if(IS_SEP(c3) || !c3) +  if(s->s->len && (IS_SEP(c3) || !c3))    {    /* Handle "..". */    int tmp=s->s->len-1;
220:    ( (tmp+2 == s->s->len) ||    IS_SEP(index_shared_string(s->s,tmp+2)))) {    break; -  } else if ((tmp+1 == s->s->len) || -  IS_SEP(index_shared_string(s->s,tmp+1))) { -  /* Previous is "." or "./". -  * Replace it with "..". -  */ -  if (tmp+1 != s->s->len) { -  /* Remove the separator. */ -  s->s->len--; +     } -  PUSH('.'); -  from += 2; -  if (c3) { -  PUSH('/'); -  from++; +     } - #if COMBINE_PATH_DEBUG > 0 -  /* s->s->str[s->s->len]=0; */ -  fprintf(stderr,"combine_path(2), TO: %s[%d]\n", -  s->s->str, s->s->len); -  fprintf(stderr,"combine_path(2), FROM (%d): %s[%d]\n", -  from, path.ptr+from, len-from); - #endif -  continue; +     } -  } -  } +        from+=(c3? 3:2);    s->s->len=tmp;