diff options
author | Eike Rathke <erack@redhat.com> | 2013-03-08 21:36:44 +0100 |
---|---|---|
committer | Fridrich Strba <fridrich@documentfoundation.org> | 2013-03-12 13:19:29 +0000 |
commit | 5dd1542bb372627167b44f1b020eab5a405fa6fa (patch) | |
tree | 66bb4901496f595cd9caea4d0c75ed00edefce4f /sw | |
parent | d4b3e398f95225951f86d3e8f7474f7a0fb86b92 (diff) |
more regex fixes, fdo#60259 related
fdo#60259 prevent crash when searching backward for $ anchor regex
Old code wasn't prepared that searching for $ may actually return a
result set pointing behind the search string which it does with the ICU
regex engine.
(cherry picked from commit c00601dab0f5533b152cd63cec0a89bfec1ba95f)
Conflicts:
i18npool/source/search/textsearch.cxx
regex: handle zero-length matches, fdo#60259 related
Also in backward search ignore all zero-length matches except the text
end single $ anchor search. The anchor search is a valid match, treat it
as such in Writer.
This still doesn't solve the backward $ backward search, the convoluted
Writer code in that place apparently never worked, someone more familiar
with those internals should straighten out the mess.
(cherry picked from commit 3bc5cb3c485d67f1ce0541d349d11637f52ebda5)
regex: don't loop 10000 identical matches to find a single $ anchor
(cherry picked from commit ccc349d3abb70ef38cd2b7706da51b060a385908)
make forward replacement of $ work again, fdo#60259 related
broken with 3bc5cb3c485d67f1ce0541d349d11637f52ebda5
(cherry picked from commit d8dcfa0e5dbecf77c4d6a8d49caf61b339cf9b43)
Change-Id: I6b5eb28d0a54ceecb6873a3c05f18f70312ab1a2
Reviewed-on: https://gerrit.libreoffice.org/2679
Reviewed-by: Fridrich Strba <fridrich@documentfoundation.org>
Tested-by: Fridrich Strba <fridrich@documentfoundation.org>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/crsr/findtxt.cxx | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/sw/source/core/crsr/findtxt.cxx b/sw/source/core/crsr/findtxt.cxx index 101b002d728e..427c4fab9efe 100644 --- a/sw/source/core/crsr/findtxt.cxx +++ b/sw/source/core/crsr/findtxt.cxx @@ -446,8 +446,9 @@ bool SwPaM::DoSearch( const SearchOptions& rSearchOpt, utl::TextSearch& rSTxt, } xub_StrLen nStringEnd = nEnd; - while ( (bSrchForward && nStart < nStringEnd) || - (! bSrchForward && nStart > nStringEnd) ) + bool bZeroMatch = false; // zero-length match, i.e. only $ anchor as regex + while ( ((bSrchForward && nStart < nStringEnd) || + (! bSrchForward && nStart > nStringEnd)) && !bZeroMatch ) { // SearchAlgorithms_APPROXIMATE works on a per word base so we have to // provide the text searcher with the correct locale, because it uses @@ -475,7 +476,8 @@ bool SwPaM::DoSearch( const SearchOptions& rSearchOpt, utl::TextSearch& rSTxt, } if( nSearchScript == nCurrScript && - (rSTxt.*fnMove->fnSearch)( sCleanStr, &nStart, &nEnd, 0 )) + (rSTxt.*fnMove->fnSearch)( sCleanStr, &nStart, &nEnd, 0 ) && + !(bZeroMatch = (nStart == nEnd))) { // set section correctly *GetPoint() = *pPam->GetPoint(); @@ -518,11 +520,14 @@ bool SwPaM::DoSearch( const SearchOptions& rSearchOpt, utl::TextSearch& rSTxt, if ( bFound ) return true; - else if( ( bChkEmptyPara && !nStart && !nTxtLen ) || bChkParaEnd ) + else if( ( bChkEmptyPara && !nStart && !nTxtLen ) || bChkParaEnd) { *GetPoint() = *pPam->GetPoint(); GetPoint()->nContent = bChkParaEnd ? nTxtLen : 0; SetMark(); + /* FIXME: this condition does not work for !bSrchForward backward + * search, it probably never did. (pSttNd != &rNdIdx.GetNode()) + * is never true in this case. */ if( (bSrchForward || pSttNd != &rNdIdx.GetNode()) && Move( fnMoveForward, fnGoCntnt ) && (!bSrchForward || pSttNd != &GetPoint()->nNode.GetNode()) && |