summaryrefslogtreecommitdiff
blob: 37f605ccf610b92cd323e3189af1202261f96ea7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
http://lists.gnu.org/archive/html/bug-zile/2011-08/msg00030.html

--- zile-2.3.24-orig/src/file.c
+++ zile-2.3.24/src/file.c
@@ -177,14 +177,15 @@ compact_path (astr path)
     {
       /* Replace `/userhome/' (if found) with `~/'. */
       size_t homelen = strlen (pw->pw_dir);
-      if (astr_len (path) >= homelen &&
-          !strncmp (pw->pw_dir, astr_cstr (path), homelen))
+      if (homelen > 0 && pw->pw_dir[homelen - 1] == '/')
+        homelen--;
+
+      if (astr_len (path) > homelen &&
+          !strncmp (pw->pw_dir, astr_cstr (path), homelen) &&
+          astr_get (path, homelen) == '/')
         {
           astr buf = astr_new_cstr ("~/");
-          if (STREQ (pw->pw_dir, "/"))
-            astr_cat_cstr (buf, astr_cstr (path) + 1);
-          else
-            astr_cat_cstr (buf, astr_cstr (path) + homelen + 1);
+          astr_cat_cstr (buf, astr_cstr (path) + homelen + 1);
           astr_cpy (path, buf);
           astr_delete (buf);
         }