editeng/qa/unit/core-test.cxx | 22 ++++++++++++++++++++++ editeng/source/editeng/impedit4.cxx | 3 --- sw/qa/extras/uiwriter/uiwriter4.cxx | 34 ++++++++++++++++++++++++++++++++++ sw/source/core/txtnode/txtedt.cxx | 3 --- 4 files changed, 56 insertions(+), 6 deletions(-)
New commits: commit b7308bda7212da5681b7047c02e2e13e36b2a98a Author: Michael Warner <michael.warner.ut+libreoff...@gmail.com> AuthorDate: Sun Feb 13 22:45:48 2022 -0500 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Thu Feb 17 17:15:16 2022 +0100 tdf#147196: Fix crash in editeng when applying title case format Fixes a possiblity of crashing when applying title case format using the edit engine. Change-Id: I4f44f635a1c96b021c084bb5bb973180744e56e2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129888 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx index f3500e01ce26..ffdec6ffb2fe 100644 --- a/editeng/qa/unit/core-test.cxx +++ b/editeng/qa/unit/core-test.cxx @@ -97,6 +97,8 @@ public: void testTransliterate(); + void testTdf147196(); + DECL_STATIC_LINK( Test, CalcFieldValueHdl, EditFieldInfo*, void ); CPPUNIT_TEST_SUITE(Test); @@ -119,6 +121,7 @@ public: CPPUNIT_TEST(testSectionAttributes); CPPUNIT_TEST(testLargeParaCopyPaste); CPPUNIT_TEST(testTransliterate); + CPPUNIT_TEST(testTdf147196); CPPUNIT_TEST_SUITE_END(); private: @@ -1830,6 +1833,17 @@ void Test::testTransliterate() CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones mET joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE)); CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE)); + /* Test behavior when there is a selection that ends in the middle of a word */ + selStart = 11; + selEnd = 13; + esel = ESelection(0, selStart, 0, selEnd); + CPPUNIT_ASSERT_EQUAL(OUString("me"), editEng.GetText(esel)); + CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones Met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::SENTENCE_CASE)); + CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones Met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE)); + CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones MEt joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE)); + CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE)); + + /* Test behavior when there is a selection that crosses a word boundary: "nes met joe Sm" */ selStart = 7; selEnd = 21; @@ -1865,9 +1879,17 @@ void Test::testTransliterate() CPPUNIT_ASSERT_EQUAL(OUString("CURRENT IS EQUAL TO 10 A"), lcl_translitTest(editEng, sText3, esel, TF::LOWERCASE_UPPERCASE)); CPPUNIT_ASSERT_EQUAL(OUString("current is equal to 10 A"), lcl_translitTest(editEng, sText3, esel, TF::UPPERCASE_LOWERCASE)); +} +void Test::testTdf147196() +{ + EditEngine editEng( mpItemPool.get() ); + editEng.SetText("2.2 Publication of information - CAA\nSection 4.2 of a CA\'s Certificate Policy and/or Certification Practice Statement SHALL state the CA\'s policy or practice on processing CAA Records for Fully Qualified Domain Names; that policy shall be consistent with these Requirements. \n\nIt shall clearly specify the set of Issuer Domain Names that the CA recognises in CAA \"issue\" or \"issuewild\" records as permitting it to issue. The CA SHALL log all actions taken, if any, consistent with its processing practice."); + editEng.TransliterateText(ESelection(0, 0, 3, 232), TransliterationFlags::TITLE_CASE); + CPPUNIT_ASSERT_EQUAL(OUString("2.2 Publication Of Information - Caa\nSection 4.2 Of A Ca\'s Certificate Policy And/Or Certification Practice Statement Shall State The Ca\'s Policy Or Practice On Processing Caa Records For Fully Qualified Domain Names; That Policy Shall Be Consistent With These Requirements. \n\nIt Shall Clearly Specify The Set Of Issuer Domain Names That The Ca Recognises In Caa \"Issue\" Or \"Issuewild\" Records As Permitting It To Issue. The Ca Shall Log All Actions Taken, If Any, Consistent With Its Processing Practice."), editEng.GetText()); } + CPPUNIT_TEST_SUITE_REGISTRATION(Test); } diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index 1228924dc634..d2a37e990846 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -2776,9 +2776,6 @@ EditSelection ImpEditEngine::TransliterateText( const EditSelection& rSelection, aCurWordBndry = _xBI->nextWord(aNodeStr, nCurrentStart, GetLocale( EditPaM( pNode, nCurrentStart + 1 ) ), nWordType); - - /* Selection may end in the middle of a word */ - aCurWordBndry.endPos = std::min(aCurWordBndry.endPos, aSel.Max().GetIndex()); } DBG_ASSERT( nCurrentEnd >= aEndBndry.endPos, "failed to reach end of transliteration" ); } diff --git a/sw/qa/extras/uiwriter/uiwriter4.cxx b/sw/qa/extras/uiwriter/uiwriter4.cxx index 6b0724eae54e..55b079756de0 100644 --- a/sw/qa/extras/uiwriter/uiwriter4.cxx +++ b/sw/qa/extras/uiwriter/uiwriter4.cxx @@ -322,6 +322,40 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest4, testTdf49033) lcl_translitTest(*pDoc, *pCursor, TF::UPPERCASE_LOWERCASE)); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest4, testTdf147196) +{ + using TF = TransliterationFlags; + SwDoc* pDoc = createSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + + // Insert the test text at the end of the document. + pWrtShell->SttEndDoc(/*bStt=*/false); + pWrtShell->Insert( + "2.2 Publication of information - CAA\nSection 4.2 of a CA\'s Certificate Policy and/or " + "Certification Practice Statement SHALL state the CA\'s policy or practice on processing " + "CAA Records for Fully Qualified Domain Names; that policy shall be consistent with these " + "Requirements. \n\nIt shall clearly specify the set of Issuer Domain Names that the CA " + "recognises in CAA \"issue\" or \"issuewild\" records as permitting it to issue. The CA " + "SHALL log all actions taken, if any, consistent with its processing practice."); + + pWrtShell->StartOfSection(); + SwShellCursor* pCursor = pWrtShell->getShellCursor(false); + pCursor->SetMark(); + for (int i = 0; i < 510; i++) + { + pCursor->Move(fnMoveForward); + } + CPPUNIT_ASSERT_EQUAL( + OUString("2.2 Publication Of Information - Caa\nSection 4.2 Of A Ca\'s Certificate Policy " + "And/Or Certification Practice Statement Shall State The Ca\'s Policy Or Practice " + "On Processing Caa Records For Fully Qualified Domain Names; That Policy Shall Be " + "Consistent With These Requirements. \n\nIt Shall Clearly Specify The Set Of " + "Issuer Domain Names That The Ca Recognises In Caa \"Issue\" Or \"Issuewild\" " + "Records As Permitting It To Issue. The Ca Shall Log All Actions Taken, If Any, " + "Consistent With Its Processing Practice."), + lcl_translitTest(*pDoc, *pCursor, TF::TITLE_CASE)); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest4, testTdf96943) { // Enable hide whitespace mode. diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx index 1ed69cb78265..28b633755a7d 100644 --- a/sw/source/core/txtnode/txtedt.cxx +++ b/sw/source/core/txtnode/txtedt.cxx @@ -1789,9 +1789,6 @@ void SwTextNode::TransliterateText( GetText(), nStt, g_pBreakIt->GetLocale(GetLang(nStt, 1)), nWordType); - - /* Selection may end in the middle of a word */ - aCurWordBndry.endPos = std::min(aCurWordBndry.endPos, selEnd); } } else if (rTrans.getType() == TransliterationFlags::SENTENCE_CASE)