From 8fb29ed259393a83e8fb5545c419543a85fc7bc9 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 31 May 2016 10:56:25 +0200 Subject: Don't alter input string in QTextLayout with ShowLineAndParagraphSeparators When ShowLineAndParagraphSeparators was set, we would replace the separator character in the user's string in some cases, since we never detached from the input string and just const_cast the pointer to the shared buffer. [ChangeLog][QtGui][Text] Fixed bug where a QTextLayout with ShowLineAndParagraphSeparators would modify the layout's input string. Task-number: QTBUG-42033 Change-Id: I92f9100b750f16e52b38b718245c13e5c4a0ebb9 Reviewed-by: Lars Knoll Reviewed-by: Konstantin Ritt --- .../auto/gui/text/qtextlayout/tst_qtextlayout.cpp | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp') diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp index de0c2d6dbe..e778232461 100644 --- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp @@ -142,6 +142,7 @@ private slots: void xToCursorForLigatures(); void cursorInNonStopChars(); void nbsp(); + void noModificationOfInputString(); private: QFont testFont; @@ -2176,5 +2177,37 @@ void tst_QTextLayout::layoutWithCustomTabStops() QVERIFY(longWidth > shortWidth); } +void tst_QTextLayout::noModificationOfInputString() +{ + QString s = QString(QChar(QChar::LineSeparator)); + { + QTextLayout layout; + layout.setText(s); + + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + QCOMPARE(s.size(), 1); + QCOMPARE(s.at(0), QChar(QChar::LineSeparator)); + } + + { + QTextLayout layout; + layout.setText(s); + + QTextOption option; + option.setFlags(QTextOption::ShowLineAndParagraphSeparators); + layout.setTextOption(option); + + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + QCOMPARE(s.size(), 1); + QCOMPARE(s.at(0), QChar(QChar::LineSeparator)); + } +} + QTEST_MAIN(tst_QTextLayout) #include "tst_qtextlayout.moc" -- cgit v1.2.3