summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2019-10-29 15:54:41 +0100
committerMichael Stahl <michael.stahl@cib.de>2019-10-30 14:44:09 +0100
commita6516c76c01b92f7d35bfb352b63af7de42b5707 (patch)
treee28c745685dffd53748c61078f10b83e4ab3bc55
parent3701a8a8197f94551a0080ca7db102c0317b2133 (diff)
writerfilter: rtftok: filter control characters
... in RTFDocumentImpl::checkUnicode(); see ooo86460-1.xls [sic] for an example. There is another caller of text() in rtfdispatchdestination.cxx:311 but it turns out that buffered text was created by text() in the first place. This shouldn't be a problem for DOCX because XML 1.0 doesn't allow the bad control characters anyway so the sax parser should report an error in that case. Change-Id: Ice45e1c3c8c7db668a4cfb8364e42addea1777ce Reviewed-on: https://gerrit.libreoffice.org/81697 Reviewed-by: Michael Stahl <michael.stahl@cib.de> Tested-by: Michael Stahl <michael.stahl@cib.de>
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx25
1 files changed, 25 insertions, 0 deletions
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index f2873ecf97b8..a2d0d1635e7c 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -30,6 +30,7 @@
#include <tools/datetimeutils.hxx>
#include <comphelper/classids.hxx>
#include <comphelper/embeddedobjectcontainer.hxx>
+#include <svl/lngmisc.hxx>
#include <sfx2/sfxbasemodel.hxx>
#include <sfx2/classificationhelper.hxx>
#include <oox/mathml/import.hxx>
@@ -3563,12 +3564,35 @@ bool RTFDocumentImpl::getSkipUnknown() { return m_bSkipUnknown; }
void RTFDocumentImpl::setSkipUnknown(bool bSkipUnknown) { m_bSkipUnknown = bSkipUnknown; }
+static auto FilterControlChars(Destination const destination, OUString const& rString) -> OUString
+{
+ if (destination == Destination::LEVELNUMBERS || destination == Destination::LEVELTEXT)
+ { // control characters are magic here!
+ return rString;
+ }
+ OUStringBuffer buf(rString.getLength());
+ for (sal_Int32 i = 0; i < rString.getLength(); ++i)
+ {
+ sal_Unicode const ch(rString[i]);
+ if (!linguistic::IsControlChar(ch) || ch == '\r' || ch == '\n' || ch == '\t')
+ {
+ buf.append(ch);
+ }
+ else
+ {
+ SAL_INFO("writerfilter.rtf", "filtering control character");
+ }
+ }
+ return buf.makeStringAndClear();
+}
+
void RTFDocumentImpl::checkUnicode(bool bUnicode, bool bHex)
{
if (bUnicode && !m_aUnicodeBuffer.isEmpty())
{
OUString aString = m_aUnicodeBuffer.toString();
m_aUnicodeBuffer.setLength(0);
+ aString = FilterControlChars(m_aStates.top().getDestination(), aString);
text(aString);
}
if (bHex && !m_aHexBuffer.isEmpty())
@@ -3579,6 +3603,7 @@ void RTFDocumentImpl::checkUnicode(bool bUnicode, bool bHex)
nEncoding = RTL_TEXTENCODING_MS_1252;
OUString aString = OStringToOUString(m_aHexBuffer.toString(), nEncoding);
m_aHexBuffer.setLength(0);
+ aString = FilterControlChars(m_aStates.top().getDestination(), aString);
text(aString);
}
}