From 07553d03534e66b13602bf41937e9221020e70d9 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Sat, 6 Jul 2019 13:13:42 +0200 Subject: QTextBrowser: assume Markdown is UTF-8 That's how CommonMark specifies it. The HTML codec-guessing algorithm was making it fall back to Latin1 in practice, which was screwing up any Unicode characters found in the markdown source. Change-Id: I4021adc4a68591ecfd56ef24971af53ce3e9c96d Reviewed-by: Gatis Paeglis --- src/widgets/widgets/qtextbrowser.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp index 2f992b1cff..7a77f86de2 100644 --- a/src/widgets/widgets/qtextbrowser.cpp +++ b/src/widgets/widgets/qtextbrowser.cpp @@ -312,13 +312,17 @@ void QTextBrowserPrivate::setSource(const QUrl &url, QTextDocument::ResourceType if (data.type() == QVariant::String) { txt = data.toString(); } else if (data.type() == QVariant::ByteArray) { + if (type == QTextDocument::HtmlResource) { #if QT_CONFIG(textcodec) - QByteArray ba = data.toByteArray(); - QTextCodec *codec = Qt::codecForHtml(ba); - txt = codec->toUnicode(ba); + QByteArray ba = data.toByteArray(); + QTextCodec *codec = Qt::codecForHtml(ba); + txt = codec->toUnicode(ba); #else - txt = data.toString(); + txt = data.toString(); #endif + } else { + txt = QString::fromUtf8(data.toByteArray()); + } } if (Q_UNLIKELY(txt.isEmpty())) qWarning("QTextBrowser: No document for %s", url.toString().toLatin1().constData()); -- cgit v1.2.3