diff options
author | Nick Kew <niq@apache.org> | 2007-10-28 13:44:19 +0100 |
---|---|---|
committer | Nick Kew <niq@apache.org> | 2007-10-28 13:44:19 +0100 |
commit | b2aeb202013ffef8ff623014c7696cddea3d7ed6 (patch) | |
tree | fae21045500e155ac56524bb079cfb5e0db7657c /modules/mappers | |
parent | Fix possible crash at startup in case of nonexistent DocumentRoot. (diff) | |
download | apache2-b2aeb202013ffef8ff623014c7696cddea3d7ed6.tar.xz apache2-b2aeb202013ffef8ff623014c7696cddea3d7ed6.zip |
Update r573831 to avoid duplicating URL-escaping code.
Ref. http://www.mail-archive.com/dev@httpd.apache.org/msg38532.html
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@589343 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'modules/mappers')
-rw-r--r-- | modules/mappers/mod_rewrite.c | 50 |
1 files changed, 4 insertions, 46 deletions
diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 18b490162a..8d0e12d4a1 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -386,7 +386,6 @@ static apr_global_mutex_t *rewrite_log_lock = NULL; /* Optional functions imported from mod_ssl when loaded: */ static APR_OPTIONAL_FN_TYPE(ssl_var_lookup) *rewrite_ssl_lookup = NULL; static APR_OPTIONAL_FN_TYPE(ssl_is_https) *rewrite_is_https = NULL; -static char *escape_uri(apr_pool_t *p, const char *path); /* * +-------------------------------------------------------+ @@ -639,46 +638,6 @@ static unsigned is_absolute_uri(char *uri) return 0; } -static const char c2x_table[] = "0123456789abcdef"; - -static APR_INLINE unsigned char *c2x(unsigned what, unsigned char prefix, - unsigned char *where) -{ -#if APR_CHARSET_EBCDIC - what = apr_xlate_conv_byte(ap_hdrs_to_ascii, (unsigned char)what); -#endif /*APR_CHARSET_EBCDIC*/ - *where++ = prefix; - *where++ = c2x_table[what >> 4]; - *where++ = c2x_table[what & 0xf]; - return where; -} - -/* - * Escapes a uri in a similar way as php's urlencode does. - * Based on ap_os_escape_path in server/util.c - */ -static char *escape_uri(apr_pool_t *p, const char *path) { - char *copy = apr_palloc(p, 3 * strlen(path) + 3); - const unsigned char *s = (const unsigned char *)path; - unsigned char *d = (unsigned char *)copy; - unsigned c; - - while ((c = *s)) { - if (apr_isalnum(c) || c == '_') { - *d++ = c; - } - else if (c == ' ') { - *d++ = '+'; - } - else { - d = c2x(c, '%', d); - } - ++s; - } - *d = '\0'; - return copy; -} - /* * escape absolute uri, which may or may not be path oriented. * So let's handle them differently. @@ -2369,16 +2328,15 @@ static char *do_expand(char *input, rewrite_ctx *ctx, rewriterule_entry *entry) if (entry && (entry->flags & RULEFLAG_ESCAPEBACKREF)) { /* escape the backreference */ char *tmp2, *tmp; - tmp = apr_palloc(pool, span + 1); - strncpy(tmp, bri->source + bri->regmatch[n].rm_so, span); - tmp[span] = '\0'; - tmp2 = escape_uri(pool, tmp); + tmp = apr_pstrndup(pool, bri->source + bri->regmatch[n].rm_so, span); + tmp2 = ap_escape_path_segment(pool, tmp); rewritelog((ctx->r, 5, ctx->perdir, "escaping backreference '%s' to '%s'", tmp, tmp2)); current->len = span = strlen(tmp2); current->string = tmp2; - } else { + } + else { current->len = span; current->string = bri->source + bri->regmatch[n].rm_so; } |