OSDN Git Service

should remove duplicated slash
authorarai <arai@6a8cc165-1e22-0410-a132-eb4e3f353aba>
Sun, 2 Mar 2008 10:21:41 +0000 (10:21 +0000)
committerarai <arai@6a8cc165-1e22-0410-a132-eb4e3f353aba>
Sun, 2 Mar 2008 10:21:41 +0000 (10:21 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/lha/lha/trunk@884 6a8cc165-1e22-0410-a132-eb4e3f353aba

ChangeLog
configure.ac
src/header.c
tests/lha-test17

index a8ef739..dd625bf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-02-21  Koji Arai  <arai@users.sourceforge.jp>
+
+       * src/header.c (canon_path): should remove duplicated slash.
+       (the function name is renamed from remove_dots().)
+
+       * tests/lha-test17: added a test for above.
+
 2008-02-17  Koji Arai  <arai@users.sourceforge.jp>
 
        * src/lhext.c (extract_one) could not extract files under readonly directories, like:
index ae6bddd..810bf2a 100644 (file)
@@ -1,5 +1,5 @@
 # Process this file with autoconf to produce a configure script.
-AC_INIT([LHa for UNIX], 1.14i-ac20080217, arai@users.sourceforge.jp, lha)
+AC_INIT([LHa for UNIX], 1.14i-ac20080221, arai@users.sourceforge.jp, lha)
 AC_DEFINE_UNQUOTED(LHA_CONFIGURE_OPTIONS, "$ac_configure_args",
            [specified options for the configure script.])
 AC_CANONICAL_HOST
index ccd7918..fa544f3 100644 (file)
@@ -1327,9 +1327,15 @@ copy_path_element(char *dst, const char *src, int size)
     return i;
 }
 
-/* remove leading "xxx/../" and "./" */
+/*
+  canonicalize path
+
+  remove leading "xxx/../"
+  remove "./", "././", "././ ... ./"
+  remove duplicated "/"
+*/
 static int
-remove_dots(char *newpath, char *path, size_t size)
+canon_path(char *newpath, char *path, size_t size)
 {
     int len;
     char *p = newpath;
@@ -1349,6 +1355,9 @@ remove_dots(char *newpath, char *path, size_t size)
             if (size <= 1)
                 break;
         }
+
+        /* remove duplicated '/' */
+        while (*path == '/') path++;
     }
 
     /* When newpath is empty, set "." */
@@ -1379,7 +1388,7 @@ init_header(name, v_stat, hdr)
     hdr->attribute = GENERIC_ATTRIBUTE;
     hdr->header_level = header_level;
 
-    len = remove_dots(hdr->name, name, sizeof(hdr->name));
+    len = canon_path(hdr->name, name, sizeof(hdr->name));
 
     hdr->crc = 0x0000;
     hdr->extend_type = EXTEND_UNIX;
index 06338ef..9e51d7b 100644 (file)
@@ -166,3 +166,27 @@ EOF
 egrep -v -- '-lh' test-tmp-stdout | diff - test-tmp-expect
                                                        check $? $LINENO
 echo -------------------------------------------------------------------
+# remove duplicated slash "xxx//xxx" -> "xxx/xxx"
+(cd test-1 &&
+  $lha c $builddir/test-tmp-10.lzh ./test-a .//test-b .///test-c
+  )
+                                                       check $? $LINENO
+$lha a test-tmp-10.lzh ./test-1/test-a .//test-1//test-b .///test-1///test-c
+
+$lha vvq test-tmp-10.lzh
+$lha vvq test-tmp-10.lzh > test-tmp-stdout
+                                                       check $? $LINENO
+# followings is sorted by argument strings.
+# XXX: this behavior is undesirable.
+cat <<"EOF" > test-tmp-expect
+test-1/test-c
+test-1/test-b
+test-1/test-a
+test-c
+test-b
+test-a
+EOF
+
+egrep -v -- '-lh' test-tmp-stdout | diff - test-tmp-expect
+                                                       check $? $LINENO
+echo -------------------------------------------------------------------