]> mj.ucw.cz Git - libucw.git/commitdiff
Libucw: Update URL escaping to current RFC (2396).
authorMichal Vaner <vorner@ucw.cz>
Tue, 22 Jul 2008 11:18:29 +0000 (13:18 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 22 Jul 2008 16:32:02 +0000 (18:32 +0200)
Add new reserved characters: '$', '+', ','
Add new allowed character: '~'

Changed NCC_xxx defines to an enum.

ucw/url.c
ucw/url.h

index 8f5073a99721aadef2b1b29526940ee5d58bc8db..f9ae9a2c22413fd8bdfafc52752671141a1c0455 100644 (file)
--- 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
        {
index 39d6e05b1a3dd52f4c55d2f6cb2430bc44f785cd..aee20715d3c2a7a6f6aae8c9bc6b52bfeaba401e 100644 (file)
--- a/ucw/url.h
+++ b/ucw/url.h
 
 /* 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 */