diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2018-10-23 20:23:22 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2018-10-24 06:56:19 +0200 |
commit | e9ab8ed391d961e42e46bbaa58a6336ff65b32b4 (patch) | |
tree | 23395417d024bf5721d74b823645ca71711c9534 /unotools | |
parent | 0378bfcea51ff0f379d0954aa6740f1829909dc3 (diff) |
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@collabora.com>
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/source/i18n/textsearch.cxx | 6 |
1 files changed, 5 insertions, 1 deletions
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; } |