wrap output it html document & body

ensure right encoding is set

BUG: 500515
This commit is contained in:
Christoph Cullmann
2025-03-30 18:27:45 +02:00
parent cfc45f4a2e
commit 7ef31a7977
2 changed files with 21 additions and 0 deletions

View File

@@ -112,6 +112,14 @@ void TerminalCharacterDecoderTest::testHTMLDecoder()
decoder->end();
delete[] testCharacters;
delete decoder;
// ensure we exported the encoding, bug 500515
QVERIFY(outputString.contains(QStringLiteral("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />")));
// strip HTML document
outputString.replace(QRegularExpression(QStringLiteral("^.*<body>\\n"), QRegularExpression::DotMatchesEverythingOption), QString());
outputString.replace(QRegularExpression(QStringLiteral("</body>.*$"), QRegularExpression::DotMatchesEverythingOption), QString());
QCOMPARE(outputString, result);
}

View File

@@ -30,6 +30,15 @@ void HTMLDecoder::begin(QTextStream *output)
{
_output = output;
// open html document & body, ensure right encoding set, bug 500515
*_output << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
*_output << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">\n";
*_output << "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
*_output << "<head>\n";
*_output << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n";
*_output << "</head>\n";
*_output << "<body>\n";
QString text;
openSpan(text, QStringLiteral("font-family:monospace"));
*output << text;
@@ -43,6 +52,10 @@ void HTMLDecoder::end()
closeSpan(text);
*_output << text;
// close body & html document
*_output << "</body>\n";
*_output << "</html>\n";
_output = nullptr;
}