Skip to content
This repository
Browse code

Test cwd_and_chdir: don't chdir to "" or "c:"

It should not strip the trailing (back)slash from a root directory.
  • Loading branch information...
commit 09a0d61e7bd4965f0a2d9219943b7eff9c3d9944 1 parent 422a898
Bert Belder authored

Showing 1 changed file with 12 additions and 9 deletions. Show diff stats Hide diff stats

  1. 21  test/test-cwd-and-chdir.c
21  test/test-cwd-and-chdir.c
@@ -37,17 +37,20 @@ TEST_IMPL(cwd_and_chdir) {
37 37
   err = uv_cwd(buffer_orig, size);
38 38
   ASSERT(err.code == UV_OK);
39 39
 
40  
-  last_slash = strrchr(buffer_orig,
  40
+  /* Remove trailing slash unless at a root directory. */
41 41
 #ifdef _WIN32
42  
-          '\\'
43  
-#else
44  
-          '/'
45  
-#endif
46  
-  );
47  
-
  42
+  last_slash = strrchr(buffer_orig, '\\');
48 43
   ASSERT(last_slash);
49  
-
50  
-  *last_slash = '\0';
  44
+  if (last_slash > buffer_orig && *(last_slash - 1) != ':') {
  45
+    *last_slash = '\0';
  46
+  }
  47
+#else /* Unix */
  48
+  last_slash = strrchr(buffer_orig, '/');
  49
+  ASSERT(last_slash);
  50
+  if (last_slash != buffer_orig) {
  51
+    *last_slash = '\0';
  52
+  }
  53
+#endif
51 54
 
52 55
   err = uv_chdir(buffer_orig);
53 56
   ASSERT(err.code == UV_OK);

0 notes on commit 09a0d61

Please sign in to comment.
Something went wrong with that request. Please try again.