[librsvg] (#425): systemLanguage: do not fail parsing if the env is broken



commit dddfcc7466f95bcba217674c03c9a1d902de42d8
Author: Paolo Angelo Borelli <pborelli gnome org>
Date:   Sat Feb 23 12:48:23 2019 +0100

    (#425): systemLanguage: do not fail parsing if the env is broken
    
    If we cannot parse the locale in the system environment, we
    should not fail to parse the svg file, we should simply ignore
    the locales we do not understand. Worse case the conditional
    will not match
    
    Fixes part of https://gitlab.gnome.org/GNOME/librsvg/issues/425

 rsvg_internals/src/cond.rs | 9 +++++----
 rsvg_internals/src/node.rs | 8 +++-----
 2 files changed, 8 insertions(+), 9 deletions(-)
---
diff --git a/rsvg_internals/src/cond.rs b/rsvg_internals/src/cond.rs
index 4099ec40..e3dface3 100644
--- a/rsvg_internals/src/cond.rs
+++ b/rsvg_internals/src/cond.rs
@@ -119,15 +119,16 @@ impl SystemLanguage {
 /// English and German).  This function converts the output of
 /// `g_get_language_names()` into a `Locale` with appropriate
 /// fallbacks.
-pub fn locale_from_environment() -> Result<Locale, String> {
+pub fn locale_from_environment() -> Locale {
     let mut locale = Locale::invariant();
 
     for name in glib::get_language_names() {
-        let range = LanguageRange::from_unix(&name).map_err(|e| format!("{}", e))?;
-        locale.add(&range);
+        if let Ok(range) = LanguageRange::from_unix(&name) {
+            locale.add(&range);
+        }
     }
 
-    Ok(locale)
+    locale
 }
 
 fn locale_accepts_language_tag(
diff --git a/rsvg_internals/src/node.rs b/rsvg_internals/src/node.rs
index 296171de..3e6be9fc 100644
--- a/rsvg_internals/src/node.rs
+++ b/rsvg_internals/src/node.rs
@@ -402,11 +402,9 @@ impl Node {
                     }
 
                     Attribute::SystemLanguage if cond => {
-                        cond = SystemLanguage::from_attribute(
-                            value,
-                            &(locale_from_environment().map_err(|e| ValueErrorKind::Value(e))?),
-                        )
-                        .map(|SystemLanguage(res)| res)?;
+                        let locale = locale_from_environment();
+                        cond = SystemLanguage::from_attribute(value, &locale)
+                            .map(|SystemLanguage(res)| res)?;
                     }
 
                     _ => {}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]