[epiphany/pgriffis/web-extension/fix-crash-on-missing-translation: 11/11] WebExtensions: Fix crash when failing to get translated string




commit 2782472b8de6b0900e0bf3e07c178502c7c91bbe
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]