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



commit 3a5637143de8157202bcc8d098b39ea79cdbd4d0
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 63f77dce..0ea8e8da 100644
--- a/rsvg_internals/src/cond.rs
+++ b/rsvg_internals/src/cond.rs
@@ -123,15 +123,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 493ae844..f148caa0 100644
--- a/rsvg_internals/src/node.rs
+++ b/rsvg_internals/src/node.rs
@@ -397,11 +397,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]