[libsoup: 1/2] Set default cookie path when origin is NULL and value not present in parsed text



commit f66d47cd5b535157cd8e96646c2300724537ca3d
Author: Adrian Perez de Castro <aperez igalia com>
Date:   Wed Jun 13 02:27:37 2018 +0200

    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

 libsoup/soup-cookie.c |  2 ++
 tests/cookies-test.c  | 10 ++++++++++
 2 files changed, 12 insertions(+)
---
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 ();
 


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