summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Perez de Castro <aperez@igalia.com>2018-06-13 02:27:37 +0200
committerAdrian Perez de Castro <aperez@igalia.com>2018-06-13 09:23:30 +0200
commitf66d47cd5b535157cd8e96646c2300724537ca3d (patch)
tree7010fb984bd6178d4bd26ab9040afce9f3db9358
parent9e84e84142e15a6201fb226222052003d5e659d6 (diff)
downloadlibsoup-f66d47cd5b535157cd8e96646c2300724537ca3d.tar.gz
Set default cookie path when origin is NULL and value not present in parsed text
This patch makes the implementation of soup_cookie_parse() match the behaviour described in the API reference documentation, which reads: If origin is NULL, path will default to "/", but domain will be left as NULL. Fixes #1
-rw-r--r--libsoup/soup-cookie.c2
-rw-r--r--tests/cookies-test.c10
2 files changed, 12 insertions, 0 deletions
diff --git a/libsoup/soup-cookie.c b/libsoup/soup-cookie.c
index 1d0dde3c..7cea82e5 100644
--- a/libsoup/soup-cookie.c
+++ b/libsoup/soup-cookie.c
@@ -299,6 +299,8 @@ parse_one_cookie (const char *header, SoupURI *origin)
slash - origin->path);
}
}
+ } else if (!cookie->path) {
+ cookie->path = g_strdup ("/");
}
return cookie;
diff --git a/tests/cookies-test.c b/tests/cookies-test.c
index 8735964c..b133f178 100644
--- a/tests/cookies-test.c
+++ b/tests/cookies-test.c
@@ -219,6 +219,15 @@ do_cookies_parsing_test (void)
soup_test_session_abort_unref (session);
}
+static void
+do_cookies_parsing_nopath_nullorigin (void)
+{
+ SoupCookie *cookie = soup_cookie_parse ("NAME=Value", NULL);
+ g_assert_nonnull (cookie);
+ g_assert_cmpstr ("/", ==, soup_cookie_get_path (cookie));
+ soup_cookie_free (cookie);
+}
+
int
main (int argc, char **argv)
{
@@ -239,6 +248,7 @@ main (int argc, char **argv)
g_test_add_func ("/cookies/accept-policy", do_cookies_accept_policy_test);
g_test_add_func ("/cookies/accept-policy-subdomains", do_cookies_subdomain_policy_test);
g_test_add_func ("/cookies/parsing", do_cookies_parsing_test);
+ g_test_add_func ("/cookies/parsing/no-path-null-origin", do_cookies_parsing_nopath_nullorigin);
ret = g_test_run ();