revert direct append to aToken in SvRTFParser::ScanText() (tdf#150151)

This reverts most of commit 09558e2f45,
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.lunak@collabora.com>
This commit is contained in:
Luboš Luňák
2022-08-12 15:34:39 +02:00
parent 3d7048552a
commit c62a987ebc
+21 -14
View File
@@ -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 )
@@ -343,10 +343,10 @@ void SvRTFParser::ScanText()
{
if (!aByteString.isEmpty())
{
aToken.append( OStringToOUString(aByteString, GetSrcEncoding()) );
aStrBuffer.append( OStringToOUString(aByteString, GetSrcEncoding()) );
aByteString.setLength(0);
}
aToken.append(static_cast<sal_Unicode>(next));
aStrBuffer.append(static_cast<sal_Unicode>(next));
continue;
}
@@ -387,7 +387,7 @@ void SvRTFParser::ScanText()
if (!aByteString.isEmpty())
{
aToken.append( OStringToOUString(aByteString, GetSrcEncoding()) );
aStrBuffer.append( OStringToOUString(aByteString, GetSrcEncoding()) );
aByteString.setLength(0);
}
}
@@ -396,16 +396,16 @@ void SvRTFParser::ScanText()
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':
@@ -418,12 +418,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
@@ -494,20 +494,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;
}
@@ -516,6 +520,9 @@ void SvRTFParser::ScanText()
if( bContinue && bNextCh )
nNextCh = GetNextChar();
}
if (!aStrBuffer.isEmpty())
aToken.append( aStrBuffer );
}