svtools/source/svrtf/parrtf.cxx | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-)
New commits: commit 7ca35790effb9a5a1ee17bd9a669fc2c38fcb99f Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Fri Aug 12 13:01:24 2022 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Mon Aug 15 13:38:38 2022 +0200 revert direct append to aToken in SvRTFParser::ScanText() (tdf#150151) This reverts most of commit 09558e2f45e27d572fd261562c884c2d2cc896a7, the problem is that GetNextToken_() resets aToken, overwriting the value created by this function. Change-Id: I1daca07a6e01cfecfeff9fbf7c311b0d392d84d4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138190 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138273 diff --git a/svtools/source/svrtf/parrtf.cxx b/svtools/source/svrtf/parrtf.cxx index c6dcef7a0b69..69fdb9508408 100644 --- a/svtools/source/svrtf/parrtf.cxx +++ b/svtools/source/svrtf/parrtf.cxx @@ -302,9 +302,9 @@ sal_Unicode SvRTFParser::GetHexValue() void SvRTFParser::ScanText() { const sal_Unicode cBreak = 0; - const sal_uInt32 nStartLength = aToken.getLength(); + OUStringBuffer aStrBuffer; bool bContinue = true; - while( bContinue && IsParserWorking() && aToken.getLength() - nStartLength < MAX_STRING_LEN) + while( bContinue && IsParserWorking() && aStrBuffer.getLength() < MAX_STRING_LEN) { bool bNextCh = true; switch( nNextCh ) @@ -342,8 +342,8 @@ void SvRTFParser::ScanText() if (next>0xFF) // fix for #i43933# and #i35653# { if (!aByteString.isEmpty()) - aToken.append( OStringToOUString(aByteString.makeStringAndClear(), GetSrcEncoding()) ); - aToken.append(static_cast<sal_Unicode>(next)); + aStrBuffer.append( OStringToOUString(aByteString.makeStringAndClear(), GetSrcEncoding()) ); + aStrBuffer.append(static_cast<sal_Unicode>(next)); continue; } @@ -383,23 +383,23 @@ void SvRTFParser::ScanText() bNextCh = false; if (!aByteString.isEmpty()) - aToken.append( OStringToOUString(aByteString.makeStringAndClear(), GetSrcEncoding()) ); + aStrBuffer.append( OStringToOUString(aByteString.makeStringAndClear(), GetSrcEncoding()) ); } break; case '\\': case '}': case '{': case '+': // I found in a RTF file - aToken.append(sal_Unicode(nNextCh)); + aStrBuffer.append(sal_Unicode(nNextCh)); break; case '~': // nonbreaking space - aToken.append(u'\x00A0'); + aStrBuffer.append(u'\x00A0'); break; case '-': // optional hyphen - aToken.append(u'\x00AD'); + aStrBuffer.append(u'\x00AD'); break; case '_': // nonbreaking hyphen - aToken.append(u'\x2011'); + aStrBuffer.append(u'\x2011'); break; case 'u': @@ -412,12 +412,12 @@ void SvRTFParser::ScanText() { bRTF_InTextRead = true; - OUString sSave( aToken ); + OUString sSave( aToken ); // GetNextToken_() overwrites this nNextCh = '\\'; int nToken = GetNextToken_(); DBG_ASSERT( RTF_U == nToken, "still not a UNI-Code character" ); // don't convert symbol chars - aToken.append(static_cast< sal_Unicode >(nTokenValue)); + aStrBuffer.append(static_cast< sal_Unicode >(nTokenValue)); // overread the next n "RTF" characters. This // can be also \{, \}, \'88 @@ -488,20 +488,24 @@ void SvRTFParser::ScanText() break; default: - if( nNextCh == cBreak || aToken.getLength() - nStartLength >= MAX_STRING_LEN) + if( nNextCh == cBreak || aStrBuffer.getLength() >= MAX_STRING_LEN) bContinue = false; else { do { // all other characters end up in the text - aToken.appendUtf32(nNextCh); + aStrBuffer.appendUtf32(nNextCh); if (sal_Unicode(EOF) == (nNextCh = GetNextChar())) + { + if (!aStrBuffer.isEmpty()) + aToken.append( aStrBuffer ); return; + } } while ( (RTF_ISALPHA(nNextCh) || RTF_ISDIGIT(nNextCh)) && - (aToken.getLength() - nStartLength < MAX_STRING_LEN) + (aStrBuffer.getLength() < MAX_STRING_LEN) ); bNextCh = false; } @@ -510,6 +514,9 @@ void SvRTFParser::ScanText() if( bContinue && bNextCh ) nNextCh = GetNextChar(); } + + if (!aStrBuffer.isEmpty()) + aToken.append( aStrBuffer ); }