[epiphany] preferences: Fix %s percent-encoding handling due to GUri port
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] preferences: Fix %s percent-encoding handling due to GUri port
- Date: Tue, 29 Jun 2021 19:36:22 +0000 (UTC)
commit 65b63759225a24e72a2d9475ecc03c4ea04ad01c
Author: vanadiae <vanadiae35 gmail com>
Date: Tue Jun 29 18:47:43 2021 +0200
preferences: Fix %s percent-encoding handling due to GUri port
It seems like SoupUri didn't default to check percent-encoding,
so this mistake wasn't caught before the GUri port, which checks
for percent-encoding, and fails here when there's %s in the URI.
Fixes b5053858dfff8fdc05180593870a559198928957
src/preferences/ephy-search-engine-row.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
---
diff --git a/src/preferences/ephy-search-engine-row.c b/src/preferences/ephy-search-engine-row.c
index 7ceeac2d1..30b0377fa 100644
--- a/src/preferences/ephy-search-engine-row.c
+++ b/src/preferences/ephy-search-engine-row.c
@@ -192,6 +192,8 @@ validate_search_engine_address (const char *address,
const char **error_message)
{
g_autoptr (GUri) uri = NULL;
+ g_autoptr (GString) uri_friendly_pattern_address = NULL;
+ guint search_terms_count = 0;
if (g_strcmp0 (address, "") == 0) {
*error_message = _("This field is required");
@@ -203,25 +205,29 @@ validate_search_engine_address (const char *address,
return FALSE;
}
- uri = g_uri_parse (address, G_URI_FLAGS_NONE, NULL);
- if (!uri) {
- *error_message = _("Address is not a valid URI");
+ uri_friendly_pattern_address = g_string_new (address);
+ /* As %s is not correctly percent-encoded, g_uri_parse() will fail here if it
+ * is in the address. So workaround this by replacing the user-facing %s with
+ * a percent-encoded %s.
+ */
+ search_terms_count = g_string_replace (uri_friendly_pattern_address,
+ "%s", "%25s", 0);
+ if (search_terms_count == 0) {
+ *error_message = _("Address must contain the search term represented by %s");
return FALSE;
- }
-
- if (!g_uri_get_host (uri) || g_strcmp0 (g_uri_get_host (uri), "") == 0) {
- *error_message = _("Address is not a valid URL. The address should look like
https://www.example.com/search?q=%s");
+ } else if (search_terms_count > 1) {
+ *error_message = _("Address should not contain the search term several times");
return FALSE;
}
- if (!g_uri_get_query (uri) || !strstr (g_uri_get_query (uri), "%s")) {
- *error_message = _("Address must contain the search term represented by %s");
+ uri = g_uri_parse (uri_friendly_pattern_address->str, G_URI_FLAGS_NONE, NULL);
+ if (!uri) {
+ *error_message = _("Address is not a valid URI");
return FALSE;
}
- /* If both are different, this means there are at least two occurences of "%s" since one starts searching
from the beginning while the other one starts from the end. */
- if (strstr (address, "%s") != g_strrstr (address, "%s")) {
- *error_message = _("Address should not contain the search term several times");
+ if (!g_uri_get_host (uri) || g_strcmp0 (g_uri_get_host (uri), "") == 0) {
+ *error_message = _("Address is not a valid URL. The address should look like
https://www.example.com/search?q=%s");
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]