libsoup r1259 - in trunk: . libsoup tests



Author: danw
Date: Fri Apr  3 00:28:39 2009
New Revision: 1259
URL: http://svn.gnome.org/viewvc/libsoup?rev=1259&view=rev

Log:
	Bug 577728 â soup_header_g_string_append_param should handle NULL values

	* libsoup/soup-headers.c (soup_header_g_string_append_param):
	allow @value to be %NULL.

	* tests/header-parsing.c (do_append_param_tests): test
	soup_header_g_string_append_param()


Modified:
   trunk/ChangeLog
   trunk/libsoup/soup-headers.c
   trunk/tests/header-parsing.c

Modified: trunk/libsoup/soup-headers.c
==============================================================================
--- trunk/libsoup/soup-headers.c	(original)
+++ trunk/libsoup/soup-headers.c	Fri Apr  3 00:28:39 2009
@@ -787,10 +787,11 @@
  * soup_header_g_string_append_param:
  * @string: a #GString being used to construct an HTTP header value
  * @name: a parameter name
- * @value: a parameter value
+ * @value: a parameter value, or %NULL
  *
- * Appends something like <literal>@name="@value"</literal> to @string,
- * taking care to appropriately escape any quotes or backslashes in @value.
+ * Appends something like <literal>@name="@value"</literal> to
+ * @string, taking care to appropriately escape any quotes or
+ * backslashes in @value.
  *
  * Alternatively, if @value is a non-ASCII UTF-8 string, it will be
  * appended using RFC2231 syntax. Although in theory this is supposed
@@ -798,6 +799,8 @@
  * reality, it can only be used portably with the Content-Disposition
  * "filename" parameter.
  *
+ * If @value is %NULL, this will just append @name to @string.
+ *
  * Since: 2.26
  **/
 void
@@ -807,6 +810,8 @@
 	const char *v;
 
 	g_string_append (string, name);
+	if (!value)
+		return;
 
 	for (v = value; *v; v++) {
 		if (*v & 0x80) {

Modified: trunk/tests/header-parsing.c
==============================================================================
--- trunk/tests/header-parsing.c	(original)
+++ trunk/tests/header-parsing.c	Fri Apr  3 00:28:39 2009
@@ -935,6 +935,45 @@
 	if (params)
 		g_hash_table_destroy (params);
 	soup_message_headers_free (hdrs);
+
+	debug_printf (1, "\n");
+}
+
+struct {
+	const char *name, *value;
+} test_params[] = {
+	{ "one", "foo" },
+	{ "two", "test with spaces" },
+	{ "three", "test with \"quotes\" and \\s" },
+	{ "four", NULL },
+	{ "five", "test with \xC3\xA1\xC3\xA7\xC4\x89\xC3\xA8\xC3\xB1\xC5\xA3\xC5\xA1" }
+};
+
+#define TEST_PARAMS_RESULT "one=\"foo\", two=\"test with spaces\", three=\"test with \\\"quotes\\\" and \\\\s\", four, five*=UTF-8''test%20with%20%C3%A1%C3%A7%C4%89%C3%A8%C3%B1%C5%A3%C5%A1"
+
+static void
+do_append_param_tests (void)
+{
+	GString *params;
+	int i;
+
+	debug_printf (1, "soup_header_g_string_append_param() tests\n");
+
+	params = g_string_new (NULL);
+	for (i = 0; i < G_N_ELEMENTS (test_params); i++) {
+		if (i > 0)
+			g_string_append (params, ", ");
+		soup_header_g_string_append_param (params,
+						   test_params[i].name,
+						   test_params[i].value);
+	}
+	if (strcmp (params->str, TEST_PARAMS_RESULT) != 0) {
+		debug_printf (1, "  FAILED!\n    expected: %s\n    got: %s\n",
+			      TEST_PARAMS_RESULT, params->str);
+		errors++;
+	} else
+		debug_printf (1, "  OK\n");
+	g_string_free (params, TRUE);
 }
 
 int
@@ -947,6 +986,7 @@
 	do_qvalue_tests ();
 	do_rfc2231_tests ();
 	do_content_type_tests ();
+	do_append_param_tests ();
 
 	test_cleanup ();
 	return errors != 0;



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