summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Vaca <albertvaka@gmail.com>2016-10-29 17:26:14 (GMT)
committerAlbert Vaca <albertvaka@gmail.com>2016-10-29 17:26:37 (GMT)
commitc8742b3f378e665a0c4e7a5baf7ccd22c236838e (patch)
tree17d769183f8d0c5bd3471a62a071eee6d15842e3
parentaa38e8d1b78f2de63c317040151640ec514660df (diff)
Fixed epub generator not being able to load resources on some files.
Cases that are fixed by this change are: - Filenames that didn't start with "/" weren't concatenated properly to the base path. - Non-normalized paths (eg: having "../") couldn't be resolved by libepub. QUrl::resolved() normalizes the paths after concatenating them. - Paths with special characters were escaped because of using QUrl::toString() instead of QUrl::path(), making them not work. Reviewed by Albert Astals.
-rw-r--r--generators/epub/epubdocument.cpp6
-rw-r--r--generators/epub/epubdocument.h2
2 files changed, 5 insertions, 3 deletions
diff --git a/generators/epub/epubdocument.cpp b/generators/epub/epubdocument.cpp
index c3f9506..1c5bb1c 100644
--- a/generators/epub/epubdocument.cpp
+++ b/generators/epub/epubdocument.cpp
@@ -47,7 +47,7 @@ void EpubDocument::setCurrentSubDocument(const QString &doc)
mCurrentSubDocument.clear();
int index = doc.indexOf('/');
if (index > 0) {
- mCurrentSubDocument = doc.left(index);
+ mCurrentSubDocument = QUrl::fromLocalFile(doc.left(index+1));
}
}
@@ -72,8 +72,10 @@ QVariant EpubDocument::loadResource(int type, const QUrl &name)
int size;
char *data;
+ QString fileInPath = mCurrentSubDocument.resolved(name).path();
+
// Get the data from the epub file
- size = epub_get_data(mEpub, (mCurrentSubDocument + name.toString()).toUtf8().constData(), &data);
+ size = epub_get_data(mEpub, fileInPath.toUtf8().constData(), &data);
QVariant resource;
diff --git a/generators/epub/epubdocument.h b/generators/epub/epubdocument.h
index eada779..64e092f 100644
--- a/generators/epub/epubdocument.h
+++ b/generators/epub/epubdocument.h
@@ -41,7 +41,7 @@ namespace Epub {
void checkCSS(QString &css);
struct epub *mEpub;
- QString mCurrentSubDocument;
+ QUrl mCurrentSubDocument;
int padding;