From: Dan Winship Date: Sat, 12 Nov 2011 14:27:33 +0000 (-0500) Subject: soup-uri: %-encode non-ASCII characters when parsing URIs X-Git-Tag: LIBSOUP_2_37_2~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=226f6382496941a4baea6c1c0d22c8d3aed634a1;p=platform%2Fupstream%2Flibsoup.git soup-uri: %-encode non-ASCII characters when parsing URIs https://bugzilla.gnome.org/show_bug.cgi?id=662806 --- diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c index 1aa801b..9170feb 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 e8568a9..285b41e 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);