[libgepub] Unscape paths before get from the archive
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgepub] Unscape paths before get from the archive
- Date: Fri, 16 Nov 2018 10:02:56 +0000 (UTC)
commit af28e5b126d542de9da6f90add9eb182eedc45cd
Author: Daniel GarcĂa Moreno <danigm wadobo com>
Date: Fri Nov 16 11:00:18 2018 +0100
Unscape paths before get from the archive
File paths can be URL encoded because the HTML stuff so we need to
unescape the string just before try to get from the archive.
I did that in the gepub-doc and not in the gepub-archive because I think
that the archive shouldn't know nothing about URL conversion.
Fix #7
libgepub/gepub-doc.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/libgepub/gepub-doc.c b/libgepub/gepub-doc.c
index 4059ac5..bb88f4c 100644
--- a/libgepub/gepub-doc.c
+++ b/libgepub/gepub-doc.c
@@ -203,6 +203,7 @@ gepub_doc_initable_init (GInitable *initable,
GepubDoc *doc = GEPUB_DOC (initable);
gchar *file;
gint i = 0, len;
+ g_autofree gchar *unescaped = NULL;
g_assert (doc->path != NULL);
@@ -215,7 +216,8 @@ gepub_doc_initable_init (GInitable *initable,
}
return FALSE;
}
- doc->content = gepub_archive_read_entry (doc->archive, file);
+ unescaped = g_uri_unescape_string (file, NULL);
+ doc->content = gepub_archive_read_entry (doc->archive, unescaped);
if (!doc->content) {
if (error != NULL) {
g_set_error (error, gepub_error_quark (), GEPUB_ERROR_INVALID,
@@ -352,7 +354,6 @@ navpoint_compare (GepubNavPoint *a, GepubNavPoint *b)
return a->playorder - b->playorder;
}
-
static void
gepub_doc_fill_toc (GepubDoc *doc, gchar *toc_id)
{
@@ -521,6 +522,7 @@ GBytes *
gepub_doc_get_resource_by_id (GepubDoc *doc, const gchar *id)
{
GepubResource *gres;
+ g_autofree gchar *unescaped = NULL;
g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
g_return_val_if_fail (id != NULL, NULL);
@@ -531,7 +533,8 @@ gepub_doc_get_resource_by_id (GepubDoc *doc, const gchar *id)
return NULL;
}
- return gepub_archive_read_entry (doc->archive, gres->uri);
+ unescaped = g_uri_unescape_string (gres->uri, NULL);
+ return gepub_archive_read_entry (doc->archive, unescaped);
}
/**
@@ -544,10 +547,16 @@ gepub_doc_get_resource_by_id (GepubDoc *doc, const gchar *id)
GBytes *
gepub_doc_get_resource (GepubDoc *doc, const gchar *path)
{
+ g_autofree gchar *unescaped = NULL;
+
g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
g_return_val_if_fail (path != NULL, NULL);
- return gepub_archive_read_entry (doc->archive, path);
+ // we need to decode the path because we can get URL encoded paths
+ // like "some%20text.jpg"
+ unescaped = g_uri_unescape_string (path, NULL);
+
+ return gepub_archive_read_entry (doc->archive, unescaped);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]