From 3bc1920fa930698851eb4c6efca45ec0f0109d8c Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Tue, 22 Jul 2008 13:18:29 +0200 Subject: [PATCH] Libucw: Update URL escaping to current RFC (2396). Add new reserved characters: '$', '+', ',' Add new allowed character: '~' Changed NCC_xxx defines to an enum. --- ucw/url.c | 15 ++++++++++----- ucw/url.h | 29 ++++++++++++++++++----------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/ucw/url.c b/ucw/url.c index 8f5073a9..f9ae9a2c 100644 --- a/ucw/url.c +++ b/ucw/url.c @@ -9,7 +9,6 @@ * * The URL syntax corresponds to RFC 2396 with several exceptions: * - * o Escaping of special characters still follows RFC 1738. * o Interpretation of path parameters follows RFC 1808. * * XXX: The buffer handling in this module is really horrible, but it works. @@ -95,6 +94,12 @@ url_deescape(const char *s, char *d) val = NCC_AND; break; case '#': val = NCC_HASH; break; + case '$': + val = NCC_DOLLAR; break; + case '+': + val = NCC_PLUS; break; + case ',': + val = NCC_COMMA; break; } *d++ = val; s += 3; @@ -133,12 +138,12 @@ url_enescape(const char *s, char *d) { if (d >= end) return URL_ERR_TOO_LONG; - if (Calnum(c) || /* RFC 1738(2.2): Only alphanumerics ... */ - c == '$' || c == '-' || c == '_' || c == '.' || c == '+' || /* ... and several other exceptions ... */ + if (Calnum(c) || /* RFC 2396 (2.1-2.3): Only alphanumerics ... */ + c == '-' || c == '_' || c == '.' || c == '+' || c == '~' || /* ... and several other exceptions ... */ c == '!' || c == '*' || c == '\'' || c == '(' || c == ')' || - c == ',' || c == '/' || c == '?' || c == ':' || c == '@' || /* ... and reserved chars used for reserved purpose */ - c == '=' || c == '&' || c == '#' || c == ';') + c == '=' || c == '&' || c == '#' || c == ';' || + c == '$' || c == '+' || c == ',') *d++ = *s++; else { diff --git a/ucw/url.h b/ucw/url.h index 39d6e05b..aee20715 100644 --- a/ucw/url.h +++ b/ucw/url.h @@ -15,17 +15,24 @@ /* Non-control meanings of control characters */ -#define NCC_SEMICOLON 1 -#define NCC_SLASH 2 -#define NCC_QUEST 3 -#define NCC_COLON 4 -#define NCC_AT 5 -#define NCC_EQUAL 6 -#define NCC_AND 7 -#define NCC_HASH 8 -#define NCC_MAX 9 - -#define NCC_CHARS " ;/?:@=&#" +enum { + NCC_SEMICOLON = 1, + NCC_SLASH = 2, + NCC_QUEST = 3, + NCC_COLON = 4, + NCC_AT = 5, + NCC_EQUAL = 6, + NCC_AND = 7, + NCC_HASH = 8, + // Avoid 9 (\t) and 10 (\n) + NCC_DOLLAR = 11, + NCC_PLUS = 12, + // Avoid 13 (\r) + NCC_COMMA = 14, + NCC_MAX = 15 +}; + +#define NCC_CHARS " ;/?:@=&#\t\n$+\r," /* Remove/Introduce '%' escapes */ -- 2.39.2