[gexiv2/postscript-dev/gexiv2-Add-catch-for-WError] Add catch clauses for `WError` exceptions
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gexiv2/postscript-dev/gexiv2-Add-catch-for-WError] Add catch clauses for `WError` exceptions
- Date: Sun, 20 Jun 2021 11:33:04 +0000 (UTC)
commit ff24907955e77b8549086b906afb08044dda81d6
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 d51977b..eb07f5f 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 c9d779f..b7d48ea 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);
+}
+
/* Regression test for https://gitlab.gnome.org/GNOME/gexiv2/issues/62 */
static void test_ggo_62(void){
GExiv2Metadata* meta = NULL;
@@ -477,6 +493,7 @@ int main(int argc, char *argv[static argc + 1])
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/62", test_ggo_62);
+ 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]