diff --git a/autotests/data/imageUrlsWithSpecialChars.md b/autotests/data/imageUrlsWithSpecialChars.md new file mode 100644 index 000000000..0d0bd1ff0 --- /dev/null +++ b/autotests/data/imageUrlsWithSpecialChars.md @@ -0,0 +1,3 @@ +# Test for having images with non-ASCII characters in their name + +![Kartöffelchen](kartöffelchen.jpg) diff --git a/autotests/data/kartöffelchen.jpg b/autotests/data/kartöffelchen.jpg new file mode 100644 index 000000000..b7dd4d188 Binary files /dev/null and b/autotests/data/kartöffelchen.jpg differ diff --git a/autotests/markdowntest.cpp b/autotests/markdowntest.cpp index 4eb0959c5..8f67f1052 100644 --- a/autotests/markdowntest.cpp +++ b/autotests/markdowntest.cpp @@ -23,6 +23,7 @@ private Q_SLOTS: void testFancyPantsEnabled(); void testFancyPantsDisabled(); void testImageSizes(); + void testSpecialCharsInImageFileName(); private: void findImages(QTextFrame *parent, QVector &images); @@ -121,5 +122,20 @@ void MarkdownTest::findImages(const QTextBlock &parent, QVectorrootFrame(); + + QVector images; + findImages(parent, images); + + QCOMPARE(images.size(), 1); + QVERIFY(images[0].name().endsWith(QStringLiteral("kartöffelchen.jpg"))); + QVERIFY(!images[0].name().contains(QStringLiteral("kart%C3%B6ffelchen.jpg"))); +} + QTEST_MAIN(MarkdownTest) #include "markdowntest.moc" diff --git a/generators/markdown/converter.cpp b/generators/markdown/converter.cpp index e4af1741d..d1c80b71b 100644 --- a/generators/markdown/converter.cpp +++ b/generators/markdown/converter.cpp @@ -197,7 +197,8 @@ void Converter::convertImages(const QTextBlock &parent, const QDir &dir, QTextDo cursor.setPosition(textFragment.position(), QTextCursor::MoveAnchor); cursor.setPosition(textFragment.position() + textFragment.length(), QTextCursor::KeepAnchor); - const QString imageFilePath = QDir::cleanPath(dir.absoluteFilePath(textCharFormat.toImageFormat().name())); + const QString imageFilePath = QDir::cleanPath(dir.absoluteFilePath(QUrl::fromPercentEncoding(textCharFormat.toImageFormat().name().toUtf8()))); + if (QFile::exists(imageFilePath)) { cursor.removeSelectedText(); format.setName(imageFilePath);