[epiphany/pgriffis/web-extension/fix-crash-on-missing-translation: 5/5] WebExtensions: Fix crash when failing to get translated string
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/pgriffis/web-extension/fix-crash-on-missing-translation: 5/5] WebExtensions: Fix crash when failing to get translated string
- Date: Tue, 30 Aug 2022 15:51:02 +0000 (UTC)
commit 5712678e81408b9b006e2825e17117a51778f929
Author: Patrick Griffis <pgriffis igalia com>
Date: Tue Aug 23 10:53:15 2022 -0500
WebExtensions: Fix crash when failing to get translated string
ephy_web_extension_manifest_get_localized_string() will now never
return NULL.
Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/1189>
src/webextension/ephy-web-extension.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/src/webextension/ephy-web-extension.c b/src/webextension/ephy-web-extension.c
index 48f67e734..c1860fa9d 100644
--- a/src/webextension/ephy-web-extension.c
+++ b/src/webextension/ephy-web-extension.c
@@ -649,10 +649,21 @@ ephy_web_extension_manifest_get_localized_string (EphyWebExtension *self,
if (g_str_has_prefix (value, "__MSG_") && g_str_has_suffix (value, "__")) {
/* FIXME: Set current locale */
g_autofree char *locale = g_strdup ("en");
+ g_autofree char *translated_string = NULL;
+ char *message_name;
- /* Remove trailing __ */
+ /* Strip prefix and remove trailing __ */
+ message_name = value + strlen ("__MSG_");
value[strlen (value) - 2] = '\0';
- return web_extension_get_translation (self, locale, value + strlen ("__MSG_"));
+
+ translated_string = web_extension_get_translation (self, locale, message_name);
+
+ if (!translated_string) {
+ g_debug ("Failed to find '%s' translation for message '%s'", locale, message_name);
+ return g_strdup ("");
+ }
+
+ return g_steal_pointer (&translated_string);
}
return g_steal_pointer (&value);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]