[libsoup] Greatly simplify soup_uri_get_path_and_query()
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] Greatly simplify soup_uri_get_path_and_query()
- Date: Wed, 27 Jan 2021 18:23:10 +0000 (UTC)
commit a709938d78cfd19aca92749c946572f2b7691c07
Author: Patrick Griffis <pgriffis igalia com>
Date: Wed Jan 27 12:22:58 2021 -0600
Greatly simplify soup_uri_get_path_and_query()
libsoup/soup-uri-utils.c | 20 +++++---------------
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]