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




commit b6b837fa260d58b95eef5202af8b3f54319a99f2
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.

 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..e19403c49 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_warning ("Failed to find 'en' translation for message '%s'", 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]