From 98e936689e1b308bc41175995b4312e8049475c8 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 22 Aug 2020 20:25:10 +0200 Subject: [PATCH] App: fix crash due to incorrect usage of std::mismatch --- src/App/PropertyLinks.cpp | 59 +++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index ac6bef20a4..567f4c3bbb 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -2463,22 +2463,19 @@ public: const char *filename, App::Document *pDoc, bool relative, QString *fullPath = 0) { bool absolute; - // The path could be an URI, in that case - // TODO: build a far much more resilient approach to test for an URI - std::string prefix("https://"); - std::string FileName(filename); - auto res = std::mismatch(prefix.begin(), prefix.end(), FileName.begin()); - if ( res.first == prefix.end() ) - { - // We do have an URI - QString path = QString::fromUtf8(filename); - if ( fullPath ) - *fullPath = path; + // The path could be an URI, in that case + // TODO: build a far much more resilient approach to test for an URI + QString path = QString::fromUtf8(filename); + if (path.startsWith(QLatin1String("https://"))) { + // We do have an URI + if (fullPath) + *fullPath = path; return std::string(filename); - } + } + // make sure the filename is aboluste path - QString path = QDir::cleanPath(QString::fromUtf8(filename)); - if((absolute=QFileInfo(path).isAbsolute())) { + path = QDir::cleanPath(path); + if((absolute = QFileInfo(path).isAbsolute())) { if(fullPath) *fullPath = path; if(!relative) @@ -2547,28 +2544,22 @@ public: } static QString getFullPath(const char *p) { - QString path = QString::fromUtf8(p);; - std::string prefix("https://"); - std::string Path(path.toStdString()); - auto res = std::mismatch(prefix.begin(), prefix.end(), Path.begin()); - if ( res.first == prefix.end() ) - return(path); - else - { - if(!p) return QString(); - return QFileInfo(QString::fromUtf8(p)).canonicalFilePath(); - } - } + QString path = QString::fromUtf8(p); + if (path.isEmpty()) + return path; + + if (path.startsWith(QLatin1String("https://"))) + return path; + else + return QFileInfo(path).canonicalFilePath(); + } QString getFullPath() const { - QString path = myPos->first; - std::string prefix("https://"); - std::string Path(path.toStdString()); - auto res = std::mismatch(prefix.begin(), prefix.end(), Path.begin()); - if ( res.first == prefix.end() ) - return(path); - else - return QFileInfo(myPos->first).canonicalFilePath(); + QString path = myPos->first; + if (path.startsWith(QLatin1String("https://"))) + return path; + else + return QFileInfo(myPos->first).canonicalFilePath(); } const char *filePath() const {