]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
fix double slash problem
authorAndré Malo <nd@apache.org>
Mon, 12 Jan 2004 14:36:17 +0000 (14:36 +0000)
committerAndré Malo <nd@apache.org>
Mon, 12 Jan 2004 14:36:17 +0000 (14:36 +0000)
Reviewed by: Jeff Trawick, Justin Erenkrantz

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x@102286 13f79535-47bb-0310-9956-ffa450edef68

src/CHANGES
src/modules/standard/mod_rewrite.c
src/modules/standard/mod_rewrite.h

index 01c5a594fcfc35912b40214be68cac34700fd56a..8cd63587fbe3455dc85f263608badedc1653412d 100644 (file)
@@ -1,5 +1,7 @@
 Changes with Apache 1.3.30
 
+  *) Fix RewriteBase directive to not add double slashes.  [André Malo]
+
   *) mod_rewrite: In external rewrite maps lookup keys containing
      a newline now cause a lookup failure. PR 14453.
      [Cedric Gavage <cedric.gavage unixtech.be>, André Malo]
index 98996a6eab89c2b9baf4e96e5815c388f94c08bf..1eb77bb6cefc239f8a57351d0561fe9e5c449ba8 100644 (file)
@@ -4122,47 +4122,49 @@ static cacheentry *retrieve_cache_string(cache *c, char *res, char *key)
 ** +-------------------------------------------------------+
 */
 
+/*
+ * substitute the prefix path 'match' in 'input' with 'subst'
+ * (think of RewriteBase which substitutes the physical path with
+ *  the virtual path)
+ */
+
 static char *subst_prefix_path(request_rec *r, char *input, char *match,
-                               char *subst)
+                               const char *subst)
 {
-    char matchbuf[LONG_STRING_LEN];
-    char substbuf[LONG_STRING_LEN];
-    char *output;
-    int l;
+    size_t len = strlen(match);
 
-    output = input;
-
-    /* first create a match string which always has a trailing slash */
-    l = ap_cpystrn(matchbuf, match, sizeof(matchbuf) - 1) - matchbuf;
-    if (!l || matchbuf[l-1] != '/') {
-       matchbuf[l] = '/';
-       matchbuf[l+1] = '\0';
-       l++;
-    }
-    /* now compare the prefix */
-    if (strncmp(input, matchbuf, l) == 0) {
-        rewritelog(r, 5, "strip matching prefix: %s -> %s", output, output+l);
-        output = ap_pstrdup(r->pool, output+l);
-
-        /* and now add the base-URL as replacement prefix */
-        l = ap_cpystrn(substbuf, subst, sizeof(substbuf) - 1) - substbuf;
-        if (!l || substbuf[l-1] != '/') {
-           substbuf[l] = '/';
-           substbuf[l+1] = '\0';
-           l++;
-        }
-        if (output[0] == '/') {
-            rewritelog(r, 4, "add subst prefix: %s -> %s%s",
-                       output, substbuf, output+1);
-            output = ap_pstrcat(r->pool, substbuf, output+1, NULL);
+    if (len && match[len - 1] == '/') {
+        --len;
+    }
+
+    if (!strncmp(input, match, len) && input[len++] == '/') {
+        size_t slen, outlen;
+        char *output;
+
+        rewritelog(r, 5, "strip matching prefix: %s -> %s", input, input+len);
+
+        slen = strlen(subst);
+        if (slen && subst[slen - 1] != '/') {
+            ++slen;
         }
-        else {
-            rewritelog(r, 4, "add subst prefix: %s -> %s%s",
-                       output, substbuf, output);
-            output = ap_pstrcat(r->pool, substbuf, output, NULL);
+
+        outlen = strlen(input) + slen - len;
+        output = ap_palloc(r->pool, outlen + 1); /* don't forget the \0 */
+
+        memcpy(output, subst, slen);
+        if (slen && !output[slen-1]) {
+            output[slen-1] = '/';
         }
+        memcpy(output+slen, input+len, outlen - slen);
+        output[outlen] = '\0';
+
+        rewritelog(r, 4, "add subst prefix: %s -> %s", input+len, output);
+
+        return output;
     }
-    return output;
+
+    /* prefix didn't match */
+    return input;
 }
 
 
index 874efebd66c517564a757d776ff200714e4742e3..d3f63aba59c733eb19c8539d5847d943ada1bb90 100644 (file)
@@ -493,7 +493,7 @@ static void   store_cache_string(cache *c, char *res, cacheentry *ce);
 
     /* misc functions */
 static char  *subst_prefix_path(request_rec *r, char *input, char *match,
-                                char *subst);
+                                const char *subst);
 static int    parseargline(char *str, char **a1, char **a2, char **a3);
 static int    prefix_stat(const char *path, ap_pool *pool);
 static void   add_env_variable(request_rec *r, char *s);