diff options
-rw-r--r-- | libsoup/soup-uri.c | 16 | ||||
-rw-r--r-- | tests/uri-parsing.c | 5 |
2 files changed, 12 insertions, 9 deletions
diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c index 1aa801b9..9170feb4 100644 --- a/libsoup/soup-uri.c +++ b/libsoup/soup-uri.c @@ -673,7 +673,7 @@ uri_normalized_copy (const char *part, int length, *d++ = *s; } } else { - if (*s == ' ') + if (!g_ascii_isgraph (*s)) need_fixup = TRUE; *d++ = *s; } @@ -681,16 +681,16 @@ uri_normalized_copy (const char *part, int length, if (need_fixup) { GString *fixed; - char *sp, *p; fixed = g_string_new (NULL); - p = normalized; - while ((sp = strchr (p, ' '))) { - g_string_append_len (fixed, p, sp - p); - g_string_append (fixed, "%20"); - p = sp + 1; + s = (guchar *)normalized; + while (*s) { + if (g_ascii_isgraph (*s)) + g_string_append_c (fixed, *s); + else + g_string_append_printf (fixed, "%%%02X", (int)*s); + s++; } - g_string_append (fixed, p); g_free (normalized); normalized = g_string_free (fixed, FALSE); } diff --git a/tests/uri-parsing.c b/tests/uri-parsing.c index e8568a96..285b41e0 100644 --- a/tests/uri-parsing.c +++ b/tests/uri-parsing.c @@ -76,7 +76,10 @@ static struct { { "http://host/path%%%", "http://host/path%%%" }, { "http://host/path%/x/", "http://host/path%/x/" }, { "http://host/path%0x/", "http://host/path%0x/" }, - { "http://host/path%ax", "http://host/path%ax" } + { "http://host/path%ax", "http://host/path%ax" }, + + /* Bug 662806; %-encode non-ASCII characters */ + { "http://host/p\xc3\xa4th/", "http://host/p%C3%A4th/" } }; static int num_abs_tests = G_N_ELEMENTS(abs_tests); |