summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2010-09-13 10:31:02 -0400
committerDan Winship <danw@gnome.org>2010-09-13 15:42:44 -0400
commit318dae530cf578b35d87dffcc1a03bced2788769 (patch)
tree6e7d03377ff893f12e2df241f1c0317eca8c96eb
parent154105dc646a20979f26e0c581cbf75a38b897bd (diff)
downloadlibsoup-318dae530cf578b35d87dffcc1a03bced2788769.tar.gz
Fix a crash when resolving URIs with both spaces and non-UTF8 chars
When using "%.*s" in a UTF-8 locale, in at least some cases, glibc requires that the string not end in something that looks like a partial UTF-8 character. This seems wrong according to the c99 spec to me, but regardless, we need to work around it. https://bugzilla.gnome.org/show_bug.cgi?id=629449
-rw-r--r--libsoup/soup-uri.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c
index e0a99427..fcafa482 100644
--- a/libsoup/soup-uri.c
+++ b/libsoup/soup-uri.c
@@ -290,8 +290,8 @@ soup_uri_new_with_base (SoupURI *base, const char *uri_string)
last = strrchr (base->path, '/');
if (last) {
- newpath = g_strdup_printf ("%.*s/%s",
- (int)(last - base->path),
+ newpath = g_strdup_printf ("%.*s%s",
+ (int)(last + 1 - base->path),
base->path,
uri->path);
} else
@@ -687,17 +687,19 @@ uri_normalized_copy (const char *part, int length,
} while (*s++);
if (fixup && need_fixup) {
- char *tmp, *sp;
- /* This code is lame, but so are people who put
- * unencoded spaces in URLs!
- */
- while ((sp = strchr (normalized, ' '))) {
- tmp = g_strdup_printf ("%.*s%%20%s",
- (int)(sp - normalized),
- normalized, sp + 1);
- g_free (normalized);
- normalized = tmp;
- };
+ 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;
+ }
+ g_string_append (fixed, p);
+ g_free (normalized);
+ normalized = g_string_free (fixed, FALSE);
}
return normalized;