diff options
author | Federico Mena Quintero <federico@gnome.org> | 2018-02-06 15:41:18 -0600 |
---|---|---|
committer | Federico Mena Quintero <federico@gnome.org> | 2018-02-06 15:41:18 -0600 |
commit | b5906eee12a0b7401be5878337f51e283f7afbb5 (patch) | |
tree | 27a6a5337d791257673b94033e31c452f37d6843 | |
parent | 2d8d5c6fae789bc7809c7d92a0aaf5200d559587 (diff) | |
download | librsvg-b5906eee12a0b7401be5878337f51e283f7afbb5.tar.gz |
Fix rsvg_handle_new_from_file() so that it will load URIs again
It is documented to being able to do so.
Add a test for this, too.
-rw-r--r-- | rsvg-base-file-util.c | 10 | ||||
-rw-r--r-- | tests/api.c | 26 |
2 files changed, 35 insertions, 1 deletions
diff --git a/rsvg-base-file-util.c b/rsvg-base-file-util.c index c4be0d59..6b2aca14 100644 --- a/rsvg-base-file-util.c +++ b/rsvg-base-file-util.c @@ -88,10 +88,18 @@ rsvg_handle_new_from_file (const gchar * file_name, GError ** error) gsize data_len; RsvgHandle *handle = NULL; GFile *file; + char *scheme; rsvg_return_val_if_fail (file_name != NULL, NULL, error); - file = g_file_new_for_path (file_name); + scheme = g_uri_parse_scheme (file_name); + if (scheme) { + file = g_file_new_for_uri (file_name); + g_free (scheme); + } else { + file = g_file_new_for_path (file_name); + } + base_uri = g_file_get_uri (file); if (!base_uri) { g_set_error (error, diff --git a/tests/api.c b/tests/api.c index 35ff499a..34b4fae3 100644 --- a/tests/api.c +++ b/tests/api.c @@ -257,6 +257,31 @@ handle_write_close_free (void) } static void +handle_new_from_file (void) +{ + char *filename = get_test_filename ("dpi.svg"); + char *uri = g_strconcat ("file://", filename, NULL); + + RsvgHandle *handle; + GError *error = NULL; + + /* rsvg_handle_new_from_file() can take both filenames and URIs */ + + handle = rsvg_handle_new_from_file (filename, &error); + g_assert (handle != NULL); + g_assert (error == NULL); + g_object_unref (handle); + + handle = rsvg_handle_new_from_file (uri, &error); + g_assert (handle != NULL); + g_assert (error == NULL); + g_object_unref (handle); + + g_free (filename); + g_free (uri); +} + +static void handle_new_from_data (void) { char *filename = get_test_filename ("dpi.svg"); @@ -457,6 +482,7 @@ main (int argc, char **argv) g_test_add_func ("/api/error_quark", error_quark); g_test_add_func ("/api/auto_generated", auto_generated); g_test_add_func ("/api/handle_write_close_free", handle_write_close_free); + g_test_add_func ("/api/handle_new_from_file", handle_new_from_file); g_test_add_func ("/api/handle_new_from_data", handle_new_from_data); g_test_add_func ("/api/handle_new_from_gfile_sync", handle_new_from_gfile_sync); g_test_add_func ("/api/handle_new_from_stream_sync", handle_new_from_stream_sync); |