# HG changeset patch # User Chris Cannam # Date 1374685977 -3600 # Node ID 12aff5a181bc6376c546ebbb27f48f99e2619ae8 # Parent 420ade1cb6da314a5717637d902238b713ebc4b0 When switching to "literal mode" for a local file path, use the original file path as passed to the FileSource ctor rather than going through QUrl. This avoids filename becoming encoded and QUrl::toString failing to decode it (as is happening with Windows paths using Qt5 currently). diff -r 420ade1cb6da -r 12aff5a181bc data/fileio/FileSource.cpp --- a/data/fileio/FileSource.cpp Wed Jul 17 15:43:42 2013 +0100 +++ b/data/fileio/FileSource.cpp Wed Jul 24 18:12:57 2013 +0100 @@ -71,6 +71,7 @@ FileSource::FileSource(QString fileOrUrl, ProgressReporter *reporter, QString preferredContentType) : + m_rawFileOrUrl(fileOrUrl), m_url(fileOrUrl, QUrl::StrictMode), m_localFile(0), m_reply(0), @@ -111,6 +112,9 @@ std::cerr << "FileSource::FileSource: Failed to open local file with URL \"" << m_url.toString() << "\"; trying again assuming filename was encoded" << std::endl; #endif m_url = QUrl::fromEncoded(fileOrUrl.toLatin1()); +#ifdef DEBUG_FILE_SOURCE + std::cerr << "FileSource::FileSource: URL is now \"" << m_url.toString() << "\"" << std::endl; +#endif init(); } @@ -282,15 +286,20 @@ #endif bool literal = false; m_localFilename = m_url.toLocalFile(); + if (m_localFilename == "") { // QUrl may have mishandled the scheme (e.g. in a DOS path) - m_localFilename = m_url.toString(); + m_localFilename = m_rawFileOrUrl; +#ifdef DEBUG_FILE_SOURCE + std::cerr << "FileSource::init: Trying literal local filename \"" + << m_localFilename << "\"" << std::endl; +#endif literal = true; } m_localFilename = QFileInfo(m_localFilename).absoluteFilePath(); #ifdef DEBUG_FILE_SOURCE - std::cerr << "FileSource::init: URL translates to local filename \"" + std::cerr << "FileSource::init: URL translates to absolute filename \"" << m_localFilename << "\" (with literal=" << literal << ")" << std::endl; #endif @@ -306,7 +315,7 @@ #endif // Again, QUrl may have been mistreating us -- // e.g. dropping a part that looks like query data - m_localFilename = m_url.toString(); + m_localFilename = m_rawFileOrUrl; literal = true; if (!QFileInfo(m_localFilename).exists()) { m_lastStatus = 404; diff -r 420ade1cb6da -r 12aff5a181bc data/fileio/FileSource.h --- a/data/fileio/FileSource.h Wed Jul 17 15:43:42 2013 +0100 +++ b/data/fileio/FileSource.h Wed Jul 24 18:12:57 2013 +0100 @@ -218,6 +218,7 @@ protected: FileSource &operator=(const FileSource &); // not provided + QString m_rawFileOrUrl; QUrl m_url; QFile *m_localFile; QNetworkReply *m_reply;