Explorar o código

fix ParseAsMarkdownAndPaste corner cases (without https protocol)

Le Tan %!s(int64=4) %!d(string=hai) anos
pai
achega
ebd65b26be
Modificáronse 2 ficheiros con 9 adicións e 3 borrados
  1. 1 1
      libs/vtextedit
  2. 8 2
      src/widgets/editors/markdowneditor.cpp

+ 1 - 1
libs/vtextedit

@@ -1 +1 @@
-Subproject commit b9c3758d1d34a2281748352902cf1d3452f24bd4
+Subproject commit ace5699b65e61dfaca1e252364a8a735048e115b

+ 8 - 2
src/widgets/editors/markdowneditor.cpp

@@ -997,6 +997,7 @@ void MarkdownEditor::parseToMarkdownAndPaste()
 void MarkdownEditor::handleHtmlToMarkdownData(quint64 p_id, TimeStamp p_timeStamp, const QString &p_text)
 {
     Q_UNUSED(p_id);
+    qDebug() << "htmlToMarkdownData" << p_timeStamp;
     if (m_timeStamp == p_timeStamp && !p_text.isEmpty()) {
         QString text(p_text);
 
@@ -1048,6 +1049,8 @@ void MarkdownEditor::fetchImagesToLocalAndReplace(QString &p_text)
             continue;
         }
 
+        qDebug() << "fetching image link" << linkText;
+
         const QString imageTitle = purifyImageTitle(regExp.cap(1).trimmed());
         QString imageUrl = regExp.cap(2).trimmed();
 
@@ -1097,9 +1100,12 @@ void MarkdownEditor::fetchImagesToLocalAndReplace(QString &p_text)
             }
             QByteArray data = vte::Downloader::download(QUrl(imageUrl));
             if (!data.isEmpty()) {
-                auto suffix = info.suffix();
+                // Prefer the suffix from the real data.
+                auto suffix = ImageUtils::guessImageSuffix(data);
                 if (suffix.isEmpty()) {
-                    suffix = ImageUtils::guessImageSuffix(data);
+                    suffix = info.suffix();
+                } else if (info.suffix() != suffix) {
+                    qWarning() << "guess a different suffix from image data" << info.suffix() << suffix;
                 }
                 tmpFile.reset(FileUtils::createTemporaryFile(suffix));
                 if (tmpFile->open() && tmpFile->write(data) > -1) {