sw/source/filter/ww8/ww8par5.cxx |   31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

New commits:
commit 84659da164ac4b06cb2fad80f0aeaf63173e8ca3
Author:     Michael Stahl <michael.st...@cib.de>
AuthorDate: Wed Oct 30 16:06:02 2019 +0100
Commit:     Thorsten Behrens <thorsten.behr...@cib.de>
CommitDate: Fri Nov 1 00:26:22 2019 +0100

    sw: WW8 import: filter control characters in GetFieldResult()
    
    Triggers the assert in SwSubFont::GetTextSize_() on ooo58234-1.doc,
    which has a field result with ^G cell separators that is converted to
    SwInputField, which inserts the field result into SwTextNode.
    
    Change-Id: Ibdb93390862a11462d62cf744bac912d6009777e
    Reviewed-on: https://gerrit.libreoffice.org/81788
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@cib.de>
    (cherry picked from commit 3a9d504b01c061f60a915b5681c8313859294118)
    Reviewed-on: https://gerrit.libreoffice.org/81831
    Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de>

diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx
index ba45f50b8600..69be973d18ee 100644
--- a/sw/source/filter/ww8/ww8par5.cxx
+++ b/sw/source/filter/ww8/ww8par5.cxx
@@ -31,6 +31,7 @@
 #include <com/sun/star/task/InteractionHandler.hpp>
 
 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
+#include <svl/lngmisc.hxx>
 #include <svl/urihelper.hxx>
 #include <svl/zforlist.hxx>
 #include <svl/zformat.hxx>
@@ -1217,7 +1218,35 @@ OUString SwWW8ImplReader::GetFieldResult( WW8FieldDesc 
const * pF )
     m_pStrm->Seek( nOldPos );
 
     //replace both CR 0x0D and VT 0x0B with LF 0x0A
-    return sRes.replace(0x0D, 0x0A).replace(0x0B, 0x0A);
+    // at least in the cases where the result is added to an SwInputField
+    // there must not be control characters in it
+    OUStringBuffer buf(sRes.getLength());
+    for (sal_Int32 i = 0; i < sRes.getLength(); ++i)
+    {
+        sal_Unicode const ch(sRes[i]);
+        if (!linguistic::IsControlChar(ch))
+        {
+            buf.append(ch);
+        }
+        else
+        {
+            switch (ch)
+            {
+                case 0x0B:
+                case '\r':
+                    buf.append('\n');
+                    break;
+                case '\n':
+                case '\t':
+                    buf.append(ch);
+                    break;
+                default:
+                    SAL_INFO("sw.ww8", "GetFieldResult(): filtering control 
character");
+                    break;
+            }
+        }
+    }
+    return buf.makeStringAndClear();
 }
 
 /*
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to