[librsvg/librsvg-2.44] (#426): Detect files vs. URIs in rsvg_handle_new_from_file() on Windows
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/librsvg-2.44] (#426): Detect files vs. URIs in rsvg_handle_new_from_file() on Windows
- Date: Sat, 17 Aug 2019 20:29:47 +0000 (UTC)
commit 69205815e08dd63c13fb1ef4a2e9231c29fda2a8
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Jul 23 12:35:40 2019 -0500
(#426): Detect files vs. URIs in rsvg_handle_new_from_file() on Windows
This uses a similar approach to the master branch, where the logic has
been rewritten in Rust, but with GFile-based functions.
This more closely mimics what g_file_new_for_commandline_arg() does,
but we don't want exactly that behavior due to its handling of encoding.
Should fix https://gitlab.gnome.org/GNOME/librsvg/issues/426
librsvg/rsvg-handle.c | 36 ++++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index 72bcacbf..50ce70fe 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -485,19 +485,43 @@ RsvgHandle *
rsvg_handle_new_from_file (const gchar *file_name, GError **error)
{
gchar *base_uri;
+ gchar *scheme;
char *data;
gsize data_len;
RsvgHandle *handle = NULL;
- GFile *file;
- char *scheme;
+ GFile *file = NULL;
+ gboolean maybe_uri;
rsvg_return_val_if_fail (file_name != NULL, NULL, error);
- scheme = g_uri_parse_scheme (file_name);
- if (scheme) {
- file = g_file_new_for_uri (file_name);
- g_free (scheme);
+ if (g_path_is_absolute (file_name)) {
+ maybe_uri = FALSE;
} else {
+ /* Is the file_name UTF-8? If not, it's definitely not a URI. */
+ maybe_uri = g_utf8_validate (file_name, -1, NULL);
+ }
+
+ if (maybe_uri) {
+ /* Try construct a URI */
+
+ file = g_file_new_for_uri (file_name);
+ base_uri = g_file_get_uri (file);
+ scheme = g_file_get_uri_scheme (file);
+ if (!(base_uri && scheme)) {
+ g_clear_object (&file);
+ maybe_uri = FALSE;
+ }
+
+ g_clear_pointer (&base_uri, g_free);
+ g_clear_pointer (&scheme, g_free);
+ }
+
+ if (!file) {
+ /* Definitely not a URI. Try parsing it as a path; verify that it's
+ * well-formed by trying to extract a URI back from it.
+ */
+
+ g_assert (!maybe_uri);
file = g_file_new_for_path (file_name);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]