[libsoup] soup-uri: %-encode non-ASCII characters when parsing URIs
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] soup-uri: %-encode non-ASCII characters when parsing URIs
- Date: Sat, 12 Nov 2011 14:28:47 +0000 (UTC)
commit 226f6382496941a4baea6c1c0d22c8d3aed634a1
Author: Dan Winship <danw gnome org>
Date: Sat Nov 12 09:27:33 2011 -0500
soup-uri: %-encode non-ASCII characters when parsing URIs
https://bugzilla.gnome.org/show_bug.cgi?id=662806
libsoup/soup-uri.c | 16 ++++++++--------
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 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]