[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 816106b7e6 1/2: Display librsvg error when loading bad SVG
From: |
Stefan Kangas |
Subject: |
master 816106b7e6 1/2: Display librsvg error when loading bad SVG |
Date: |
Thu, 8 Sep 2022 21:14:49 -0400 (EDT) |
branch: master
commit 816106b7e6a930d55e723e7c4d9d5f664ecd5520
Author: Stefan Kangas <stefankangas@gmail.com>
Commit: Stefan Kangas <stefankangas@gmail.com>
Display librsvg error when loading bad SVG
* src/image.c (svg_load_image): Display the error message from librsvg
when parsing a bad SVG image file.
* test/manual/image-tests.el
(image-tests-load-image/svg-invalid): New test.
---
src/image.c | 14 +++++++-------
test/manual/image-tests.el | 11 +++++++++++
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/src/image.c b/src/image.c
index f5004c2c4c..549fe30ef7 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1,6 +1,6 @@
/* Functions for image support on window system.
-Copyright (C) 1989, 1992-2022 Free Software Foundation, Inc.
+Copyright (C) 1989-2022 Free Software Foundation, Inc.
This file is part of GNU Emacs.
@@ -11491,7 +11491,7 @@ svg_load_image (struct frame *f, struct image *img,
char *contents,
if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0))
{
g_object_unref (pixbuf);
- return 0;
+ return false;
}
init_color_table ();
@@ -11536,7 +11536,7 @@ svg_load_image (struct frame *f, struct image *img,
char *contents,
image_put_x_image (f, img, ximg, 0);
}
- return 1;
+ return true;
rsvg_error:
if (rsvg_handle)
@@ -11547,11 +11547,11 @@ svg_load_image (struct frame *f, struct image *img,
char *contents,
if (css && !STRINGP (lcss))
xfree (css);
#endif
- /* FIXME: Use error->message so the user knows what is the actual
- problem with the image. */
- image_error ("Error parsing SVG image");
+ image_error ("Error parsing SVG image: %s",
+ /* The -1 removes an extra newline. */
+ make_string (err->message, strlen (err->message) - 1));
g_clear_error (&err);
- return 0;
+ return false;
}
#endif /* defined (HAVE_RSVG) */
diff --git a/test/manual/image-tests.el b/test/manual/image-tests.el
index 2565ff29c9..c726845bd3 100644
--- a/test/manual/image-tests.el
+++ b/test/manual/image-tests.el
@@ -78,6 +78,17 @@
(image-tests-make-load-image-test 'xbm)
(image-tests-make-load-image-test 'xpm)
+(ert-deftest image-tests-load-image/svg-invalid ()
+ (with-temp-buffer
+ (pop-to-buffer (current-buffer))
+ (insert (propertize " "
+ 'display '(image :data
+ "invalid foo bar"
+ :type svg)))
+ (redisplay))
+ (with-current-buffer "*Messages*"
+ (should (string-search "XML parse error" (buffer-string)))))
+
;;;; image-test-size