diff options
author | Jakob Truelsen <antialize@gmail.com> | 2010-05-03 19:08:10 (GMT) |
---|---|---|
committer | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-05-04 09:14:12 (GMT) |
commit | e9f9887cfb6f3eace17640cb951f847d2e4a8c53 (patch) | |
tree | 02c82f8c2cc5a7e2dbefa3eb34b87ae66ac93be9 /tests/auto/qprinter | |
parent | 3326a5811fbd50add0aa370af39f4a69b3a5480e (diff) | |
download | Qt-e9f9887cfb6f3eace17640cb951f847d2e4a8c53.zip Qt-e9f9887cfb6f3eace17640cb951f847d2e4a8c53.tar.gz Qt-e9f9887cfb6f3eace17640cb951f847d2e4a8c53.tar.bz2 |
Propperly escape title and creator in PDF documents
The title and creator fields in the PDF information
section were not propperly escaped leading to invalid
pdf documents when the title contain ')','(','\' (or
any of the bazilion utf16 characters where one of the
bytes happen to be the same as the ascii code for
one of these).
Merge-request: 2375
Reviewed-by: Benjamin Poulain <benjamin.poulain@nokia.com>
Diffstat (limited to 'tests/auto/qprinter')
-rw-r--r-- | tests/auto/qprinter/tst_qprinter.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/auto/qprinter/tst_qprinter.cpp b/tests/auto/qprinter/tst_qprinter.cpp index 49bddb2..8b79533 100644 --- a/tests/auto/qprinter/tst_qprinter.cpp +++ b/tests/auto/qprinter/tst_qprinter.cpp @@ -110,6 +110,7 @@ private slots: void testCurrentPage(); void taskQTBUG4497_reusePrinterOnDifferentFiles(); + void testPdfTitle(); private: }; @@ -417,7 +418,7 @@ void tst_QPrinter::testMargins() printer.setFullPage(fullpage); printer.setPageSize((QPrinter::PageSize)pagesize); if (withPainter) - painter = new QPainter(&printer); + painter = new QPainter(&printer); #ifdef QT3_SUPPORT Q3PaintDeviceMetrics metrics(&printer); @@ -1028,5 +1029,30 @@ void tst_QPrinter::testCurrentPage() } +void tst_QPrinter::testPdfTitle() +{ + // Check the document name is represented correctly in produced pdf + { + QPainter painter; + QPrinter printer; + // This string is just the UTF-8 encoding of the string: \()f ø hiragana o + const char title[]={0x5c, 0x28, 0x29, 0x66, 0xc3, 0xb8, 0xe3, 0x81, 0x8a, 0x00}; + printer.setOutputFileName("file.pdf"); + printer.setDocName(QString::fromUtf8(title)); + painter.begin(&printer); + painter.end(); + } + QFile file("file.pdf"); + QVERIFY(file.open(QIODevice::ReadOnly)); + // The we expect the title to appear in the PDF as: + // ASCII('\title (') UTF16(\\\(\)f ø hiragana o) ASCII(')'). + // which has the following binary representation + const char expected[] = { + 0x2f, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x20, 0x28, 0xfe, + 0xff, 0x00, 0x5c, 0x5c, 0x00, 0x5c, 0x28, 0x00, 0x5c, + 0x29, 0x00, 0x66, 0x00, 0xf8, 0x30, 0x4a, 0x29}; + QVERIFY(file.readAll().contains(QByteArray(expected, 26))); +} + QTEST_MAIN(tst_QPrinter) #include "tst_qprinter.moc" |