You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by rj...@apache.org on 2013/10/03 12:33:51 UTC

svn commit: r1528791 - in /apr/apr/branches/1.5.x: ./ file_io/win32/filepath.c test/testnames.c

Author: rjung
Date: Thu Oct  3 10:33:51 2013
New Revision: 1528791

URL: http://svn.apache.org/r1528791
Log:
Remove assumption that drive letters are always uppercase.

* file_io/win32/filepath.c:
  (same_drive): new helper function
  (apr_filepath_merge): use helper rather than a simple comparison

* test/testnames.c:
  (merge_lowercasedrive): do some tests with lowercase drive names

Patch by: Bert Huijben <bert {at} qqmail.nl>

Backport of r960665 from trunk.
Had already been applied to 1.4.x as
r1099173 and r1099181.

Modified:
    apr/apr/branches/1.5.x/   (props changed)
    apr/apr/branches/1.5.x/file_io/win32/filepath.c
    apr/apr/branches/1.5.x/test/testnames.c

Propchange: apr/apr/branches/1.5.x/
------------------------------------------------------------------------------
  Merged /apr/apr/trunk:r960665

Modified: apr/apr/branches/1.5.x/file_io/win32/filepath.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/file_io/win32/filepath.c?rev=1528791&r1=1528790&r2=1528791&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/file_io/win32/filepath.c (original)
+++ apr/apr/branches/1.5.x/file_io/win32/filepath.c Thu Oct  3 10:33:51 2013
@@ -327,6 +327,27 @@ APR_DECLARE(apr_status_t) apr_filepath_r
 #endif /* ndef(NETWARE) */
 }
 
+#if !defined(NETWARE)
+static int same_drive(const char *path1, const char *path2)
+{
+    char drive1 = path1[0];
+    char drive2 = path2[0];
+
+    if (!drive1 || !drive2 || path1[1] != ':' || path2[1] != ':')
+        return FALSE;
+
+    if (drive1 == drive2)
+        return TRUE;
+
+    if (drive1 >= 'a' && drive1 <= 'z')
+        drive1 += 'A' - 'a';
+
+    if (drive2 >= 'a' && drive2 <= 'z')
+        drive2 += 'A' - 'a';
+
+    return (drive1 == drive2);
+}
+#endif
 
 APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath, 
                                              const char *basepath, 
@@ -540,7 +561,7 @@ APR_DECLARE(apr_status_t) apr_filepath_m
              * use the basepath _if_ it matches this drive letter!
              * Otherwise we must discard the basepath.
              */
-            if (addroot[0] == baseroot[0] && baseroot[1] == ':') {
+            if (same_drive(addroot, baseroot)) {
 #endif
                 /* Base the result path on the basepath
                  */

Modified: apr/apr/branches/1.5.x/test/testnames.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/test/testnames.c?rev=1528791&r1=1528790&r2=1528791&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/test/testnames.c (original)
+++ apr/apr/branches/1.5.x/test/testnames.c Thu Oct  3 10:33:51 2013
@@ -21,6 +21,11 @@
 #include "apr_general.h"
 #include "apr_pools.h"
 #include "apr_lib.h"
+#include "apr_strings.h"
+
+#if defined(WIN32)
+#include <direct.h>
+#endif
 
 #if defined(WIN32) || defined(OS2)
 #define ABS_ROOT "C:/"
@@ -175,6 +180,42 @@ static void merge_notabs(abts_case *tc, 
     ABTS_STR_EQUAL(tc, "foo/baz", dstpath);
 }
 
+#if defined (WIN32)
+static void merge_lowercasedrive(abts_case *tc, void *data)
+{
+  char current_dir[1024];
+  char current_dir_on_C[1024];
+  char *dir_on_c;
+  char *testdir;
+  apr_status_t rv;
+
+  /* Change the current directory on C: from something like "C:\dir"
+     to something like "c:\dir" to replicate the failing case. */
+  ABTS_PTR_NOTNULL(tc, _getcwd(current_dir, sizeof(current_dir)));
+
+   /* 3 stands for drive C: */
+  ABTS_PTR_NOTNULL(tc, _getdcwd(3, current_dir_on_C,
+	                            sizeof(current_dir_on_C)));
+
+  /* Use the same path, but now with a lower case driveletter */
+  dir_on_c = apr_pstrdup(p, current_dir_on_C);
+  dir_on_c[0] = (char)tolower(dir_on_c[0]);
+
+  chdir(dir_on_c);
+
+  /* Now merge a drive relative path with an upper case drive letter. */
+  rv = apr_filepath_merge(&testdir, NULL, "C:hi",
+                          APR_FILEPATH_NOTRELATIVE, p);
+
+  /* Change back to original directory for next tests */
+  chdir("C:\\"); /* Switch to upper case */
+  chdir(current_dir_on_C); /* Switch cwd on C: */
+  chdir(current_dir); /* Switch back to original cwd */
+
+  ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+}
+#endif
+
 static void root_absolute(abts_case *tc, void *data)
 {
     apr_status_t rv;
@@ -298,6 +339,9 @@ abts_suite *testnames(abts_suite *suite)
     abts_run_test(suite, merge_notabs, NULL);
     abts_run_test(suite, merge_notabsfail, NULL);
     abts_run_test(suite, merge_dotdot_dotdot_dotdot, NULL);
+#if defined(WIN32)
+    abts_run_test(suite, merge_lowercasedrive, NULL);
+#endif
 
     abts_run_test(suite, root_absolute, NULL);
     abts_run_test(suite, root_relative, NULL);