[libsoup] soup-uri: fix uri_normalized_copy to not always do fixup



commit acc39b2e08cc8f8f729fd111c686168b4788a4c3
Author: Dan Winship <danw gnome org>
Date:   Mon Jul 16 12:04:52 2012 -0400

    soup-uri: fix uri_normalized_copy to not always do fixup
    
    need_fixup was always getting set, because the trailing NUL character
    was being processed by the loop. Fix.
    
    Pointed out by Yann SOUBEYRAND,
    https://bugzilla.gnome.org/show_bug.cgi?id=680018

 libsoup/soup-uri.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c
index f4422ce..382a2a9 100644
--- a/libsoup/soup-uri.c
+++ b/libsoup/soup-uri.c
@@ -694,11 +694,11 @@ uri_normalized_copy (const char *part, int length,
 	gboolean need_fixup = FALSE;
 
 	s = d = (unsigned char *)normalized;
-	do {
+	while (*s) {
 		if (*s == '%') {
 			if (!g_ascii_isxdigit (s[1]) ||
 			    !g_ascii_isxdigit (s[2])) {
-				*d++ = *s;
+				*d++ = *s++;
 				continue;
 			}
 
@@ -706,7 +706,7 @@ uri_normalized_copy (const char *part, int length,
 			if (soup_char_is_uri_unreserved (c) ||
 			    (unescape_extra && strchr (unescape_extra, c))) {
 				*d++ = c;
-				s += 2;
+				s += 3;
 			} else {
 				/* We leave it unchanged. We used to uppercase percent-encoded
 				 * triplets but we do not do it any more as RFC3986 Section 6.2.2.1
@@ -714,14 +714,15 @@ uri_normalized_copy (const char *part, int length,
 				 */
 				*d++ = *s++;
 				*d++ = *s++;
-				*d++ = *s;
+				*d++ = *s++;
 			}
 		} else {
 			if (!g_ascii_isgraph (*s))
 				need_fixup = TRUE;
-			*d++ = *s;
+			*d++ = *s++;
 		}
-	} while (*s++);
+	}
+	*d = '\0';
 
 	if (need_fixup) {
 		GString *fixed;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]