[Libreoffice-commits] core.git: unotools/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Oct 24 04:56:42 UTC 2018


 unotools/source/i18n/textsearch.cxx |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

New commits:
commit e9ab8ed391d961e42e46bbaa58a6336ff65b32b4
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Tue Oct 23 20:23:22 2018 +0200
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Oct 24 06:56:19 2018 +0200

    Fix empty capture group reference
    
    Searching for something like (foo)|(bar) and replacing with $1$2 would fail
    assertion in appendCopy in include/rtl/ustrbuf.hxx, because beginIndex is
    negative (-1), because one of the references is always empty (SearchResult
    at TextSearch::ReplaceBackReferences() has both startOffset and startOffset
    equal to -1).
    
    In this case, we should simply return an empty string.
    
    Change-Id: Ibf91b1d17ab21c279cfcdc31e84d0c2eae567a53
    Reviewed-on: https://gerrit.libreoffice.org/62248
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/unotools/source/i18n/textsearch.cxx b/unotools/source/i18n/textsearch.cxx
index 5bb4dfd81a4a..12504ccf0882 100644
--- a/unotools/source/i18n/textsearch.cxx
+++ b/unotools/source/i18n/textsearch.cxx
@@ -329,7 +329,11 @@ void TextSearch::ReplaceBackReferences( OUString& rReplaceStr, const OUString &r
                         {
                             sal_Int32 nSttReg = rResult.startOffset[j];
                             sal_Int32 nRegLen = rResult.endOffset[j];
-                            if( nRegLen > nSttReg )
+                            if (nSttReg < 0 || nRegLen < 0) // A "not found" optional capture
+                            {
+                                nSttReg = nRegLen = 0; // Copy empty string
+                            }
+                            else if (nRegLen >= nSttReg)
                             {
                                 nRegLen = nRegLen - nSttReg;
                             }


More information about the Libreoffice-commits mailing list