diff options
author | Patrick Griffis <pgriffis@igalia.com> | 2021-01-27 12:22:58 -0600 |
---|---|---|
committer | Patrick Griffis <pgriffis@igalia.com> | 2021-01-27 12:22:58 -0600 |
commit | a709938d78cfd19aca92749c946572f2b7691c07 (patch) | |
tree | 7cf1f87afc8f25911dc4836a2c1377ae8dfe8797 | |
parent | 63ddaa3b7f4d694b06a182695c2d9484e7ef9dea (diff) | |
download | libsoup-a709938d78cfd19aca92749c946572f2b7691c07.tar.gz |
Greatly simplify soup_uri_get_path_and_query()
-rw-r--r-- | libsoup/soup-uri-utils.c | 20 | ||||
-rw-r--r-- | tests/uri-parsing-test.c | 3 |
2 files changed, 8 insertions, 15 deletions
diff --git a/libsoup/soup-uri-utils.c b/libsoup/soup-uri-utils.c index 0aac9784..f29a5e32 100644 --- a/libsoup/soup-uri-utils.c +++ b/libsoup/soup-uri-utils.c @@ -135,25 +135,15 @@ soup_uri_equal (GUri *uri1, GUri *uri2) char * soup_uri_get_path_and_query (GUri *uri) { - char *path_and_query; - gsize len; + const char *query; g_return_val_if_fail (uri != NULL, NULL); - /* An empty string is passed instead of NULL for host to prevent critical assertion if path begins with "//" - as per https://tools.ietf.org/html/rfc3986#section-3 */ - path_and_query = g_uri_join_with_user (SOUP_HTTP_URI_FLAGS, - NULL, NULL, NULL, NULL, "", -1, - g_uri_get_path (uri), - g_uri_get_query (uri), - NULL); + query = g_uri_get_query (uri); - /* The empty host results in starting with `//` which we strip off */ - len = strlen (path_and_query); - memmove (path_and_query, path_and_query + 2, len - 2); - path_and_query[len - 2] = '\0'; - - return path_and_query; + return g_strdup_printf ("%s%c%s", g_uri_get_path (uri), + query ? '?' : '\0', + query ? query : ""); } /** diff --git a/tests/uri-parsing-test.c b/tests/uri-parsing-test.c index 48e3964e..7302cf4e 100644 --- a/tests/uri-parsing-test.c +++ b/tests/uri-parsing-test.c @@ -163,6 +163,9 @@ static struct { { "https://simple/one?two", "/one?two" }, { "https://double_path//one?two", "//one?two" }, { "https://empty", "/" }, + { "https://only_query/?two", "/?two" }, + { "https://trailing_query/one?", "/one?" }, + { "https://path_only/one", "/one" }, }; static void |