[gexiv2/gexiv2-0.12: 7/8] Add catch clauses for `WError` exceptions




commit a844b529d584ec39a7e2485bdcd70805c62a075f
Author: postscript-dev <43813-postscript-dev users noreply gitlab gnome org>
Date:   Mon May 17 15:02:10 2021 +0100

    Add catch clauses for `WError` exceptions
    
    When using Exiv2 on Windows, some functions can throw `Exiv2::WError` and
    `Exiv2::Error` exceptions.
    
    + Added `Exiv2::WError` catch clauses to load/save file functions. Expect that
      wherever `std::wstring` is passed as parameter to Exiv2, has the potential
      to throw an `Exiv2::WError`
    + Added test file
    + Added regression test, checking `gexiv2_metadata_open_path()`
    
    Closes issue GNOME/gexiv2#66

 gexiv2/gexiv2-metadata.cpp | 17 ++++++++++++++++-
 test/data/partial_xml.txt  |  2 ++
 test/gexiv2-regression.c   | 17 +++++++++++++++++
 3 files changed, 35 insertions(+), 1 deletion(-)
---
diff --git a/gexiv2/gexiv2-metadata.cpp b/gexiv2/gexiv2-metadata.cpp
index 6448c2b..4751bcf 100644
--- a/gexiv2/gexiv2-metadata.cpp
+++ b/gexiv2/gexiv2-metadata.cpp
@@ -455,7 +455,12 @@ gboolean gexiv2_metadata_open_path(GExiv2Metadata* self, const gchar* path, GErr
     } catch (Exiv2::Error &e) {
         g_set_error_literal (error, g_quark_from_string ("GExiv2"), e.code (), e.what ());
     }
-    
+#ifdef EXV_UNICODE_PATH
+    catch (Exiv2::WError &e) {
+        g_set_error_literal (error, g_quark_from_string ("GExiv2"), e.code (), e.what ());
+    }
+#endif
+
     return FALSE;
 }
 
@@ -636,6 +641,11 @@ gboolean gexiv2_metadata_save_external (GExiv2Metadata *self, const gchar *path,
     } catch (Exiv2::Error &e) {
         g_set_error_literal (error, g_quark_from_string ("GExiv2"), e.code (), e.what ());
     }
+#ifdef EXV_UNICODE_PATH
+    catch (Exiv2::WError &e) {
+        g_set_error_literal (error, g_quark_from_string ("GExiv2"), e.code (), e.what ());
+    }
+#endif
 
     return FALSE;
 }
@@ -657,6 +667,11 @@ gboolean gexiv2_metadata_save_file (GExiv2Metadata *self, const gchar *path, GEr
     } catch (Exiv2::Error &e) {
         g_set_error_literal (error, g_quark_from_string ("GExiv2"), e.code (), e.what ());
     }
+#ifdef EXV_UNICODE_PATH
+    catch (Exiv2::WError &e) {
+        g_set_error_literal (error, g_quark_from_string ("GExiv2"), e.code (), e.what ());
+    }
+#endif
     
     return FALSE;
 }
diff --git a/test/data/partial_xml.txt b/test/data/partial_xml.txt
new file mode 100644
index 0000000..7da92f9
--- /dev/null
+++ b/test/data/partial_xml.txt
@@ -0,0 +1,2 @@
+<rdf:RDF xmlns:rdf='
+
diff --git a/test/gexiv2-regression.c b/test/gexiv2-regression.c
index 2cd0599..115ce84 100644
--- a/test/gexiv2-regression.c
+++ b/test/gexiv2-regression.c
@@ -327,6 +327,22 @@ static void test_ggo_58(void) {
     g_clear_object(&meta);
 }
 
+// Regression test for https://gitlab.gnome.org/GNOME/gexiv2/issues/66
+static void test_ggo_66(void) {
+    GExiv2Metadata* meta = NULL;
+    gboolean result = FALSE;
+    GError* error = NULL;
+
+    meta = gexiv2_metadata_new();
+    g_assert_nonnull(meta);
+
+    result = gexiv2_metadata_open_path(meta, SAMPLE_PATH "/partial_xml.txt", &error);
+    g_assert_nonnull(error);
+    g_assert_false(result);
+
+    g_clear_object(&meta);
+}
+
 int main(int argc, char *argv[static argc + 1])
 {
     g_test_init(&argc, &argv, NULL);
@@ -341,6 +357,7 @@ int main(int argc, char *argv[static argc + 1])
     g_test_add_func("/bugs/gnome/gitlab/xx", test_ggo_xx);
     g_test_add_func("/bugs/gnome/gitlab/45", test_ggo_45);
     g_test_add_func("/bugs/gnome/gitlab/58", test_ggo_58);
+    g_test_add_func("/bugs/gnome/gitlab/60", test_ggo_66);
 
     return g_test_run();
 }


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