You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by nd...@apache.org on 2004/01/12 15:36:17 UTC
cvs commit: apache-1.3/src/modules/standard mod_rewrite.c mod_rewrite.h
nd 2004/01/12 06:36:17
Modified: src CHANGES
src/modules/standard mod_rewrite.c mod_rewrite.h
Log:
fix double slash problem
Reviewed by: Jeff Trawick, Justin Erenkrantz
Revision Changes Path
1.1917 +2 -0 apache-1.3/src/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/apache-1.3/src/CHANGES,v
retrieving revision 1.1916
retrieving revision 1.1917
diff -u -u -r1.1916 -r1.1917
--- CHANGES 12 Jan 2004 02:05:18 -0000 1.1916
+++ CHANGES 12 Jan 2004 14:36:17 -0000 1.1917
@@ -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]
1.191 +37 -35 apache-1.3/src/modules/standard/mod_rewrite.c
Index: mod_rewrite.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_rewrite.c,v
retrieving revision 1.190
retrieving revision 1.191
diff -u -u -r1.190 -r1.191
--- mod_rewrite.c 12 Jan 2004 02:05:19 -0000 1.190
+++ mod_rewrite.c 12 Jan 2004 14:36:17 -0000 1.191
@@ -4122,47 +4122,49 @@
** +-------------------------------------------------------+
*/
+/*
+ * 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;
-
- 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++;
+ size_t len = strlen(match);
+
+ if (len && match[len - 1] == '/') {
+ --len;
}
- /* 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 (!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;
}
1.89 +1 -1 apache-1.3/src/modules/standard/mod_rewrite.h
Index: mod_rewrite.h
===================================================================
RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_rewrite.h,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -u -r1.88 -r1.89
--- mod_rewrite.h 1 Jan 2004 13:32:56 -0000 1.88
+++ mod_rewrite.h 12 Jan 2004 14:36:17 -0000 1.89
@@ -493,7 +493,7 @@
/* 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);