Kaydet (Commit) 68c72dfb authored tarafından Zolnai Tamás's avatar Zolnai Tamás

Fix assertion in xmlparse and call this function with more care

Plus change range to [nStart,nEnd).

Change-Id: I1570d07fdc90a6b2bdf3eef7914958212cbbaa87
üst 8d176543
...@@ -1180,9 +1180,10 @@ static icu::UnicodeString lcl_QuotRange( ...@@ -1180,9 +1180,10 @@ static icu::UnicodeString lcl_QuotRange(
const sal_Int32 nEnd, bool bInsideTag = false ) const sal_Int32 nEnd, bool bInsideTag = false )
{ {
icu::UnicodeString sReturn; icu::UnicodeString sReturn;
assert( nStart < nEnd );
assert( nStart >= 0 ); assert( nStart >= 0 );
assert( nEnd < rString.length() ); assert( nEnd <= rString.length() );
for (sal_Int32 i = nStart; i <= nEnd; ++i) for (sal_Int32 i = nStart; i < nEnd; ++i)
{ {
switch (rString[i]) switch (rString[i])
{ {
...@@ -1258,20 +1259,22 @@ OUString XMLUtil::QuotHTML( const OUString &rString ) ...@@ -1258,20 +1259,22 @@ OUString XMLUtil::QuotHTML( const OUString &rString )
while( aRegexMatcher.find(nStartPos, nIcuErr) && nIcuErr == U_ZERO_ERROR ) while( aRegexMatcher.find(nStartPos, nIcuErr) && nIcuErr == U_ZERO_ERROR )
{ {
nStartPos = aRegexMatcher.start(nIcuErr); nStartPos = aRegexMatcher.start(nIcuErr);
sReturn.append(lcl_QuotRange(sSource, nEndPos, nStartPos-1)); if ( nEndPos < nStartPos )
sReturn.append(lcl_QuotRange(sSource, nEndPos, nStartPos));
nEndPos = aRegexMatcher.end(nIcuErr); nEndPos = aRegexMatcher.end(nIcuErr);
icu::UnicodeString sMatch = aRegexMatcher.group(nIcuErr); icu::UnicodeString sMatch = aRegexMatcher.group(nIcuErr);
if( lcl_isTag(sMatch) ) if( lcl_isTag(sMatch) )
{ {
sReturn.append("<"); sReturn.append("<");
sReturn.append(lcl_QuotRange(sSource, nStartPos+1, nEndPos-2, true)); sReturn.append(lcl_QuotRange(sSource, nStartPos+1, nEndPos-1, true));
sReturn.append(">"); sReturn.append(">");
} }
else else
sReturn.append(lcl_QuotRange(sSource, nStartPos, nEndPos-1)); sReturn.append(lcl_QuotRange(sSource, nStartPos, nEndPos));
++nStartPos; ++nStartPos;
} }
sReturn.append(lcl_QuotRange(sSource, nEndPos, sSource.length()-1)); if( nEndPos < sSource.length() )
sReturn.append(lcl_QuotRange(sSource, nEndPos, sSource.length()));
sReturn.append('\0'); sReturn.append('\0');
return OUString(reinterpret_cast<const sal_Unicode*>(sReturn.getBuffer())); return OUString(reinterpret_cast<const sal_Unicode*>(sReturn.getBuffer()));
} }
......
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