Kaydet (Commit) e9ab8ed3 authored tarafından Mike Kaganski's avatar Mike Kaganski

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: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 0378bfce
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment