[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.3' - sw/qa sw/source
Mike Kaganski
mike.kaganski at collabora.com
Thu Jan 18 14:50:31 UTC 2018
sw/qa/extras/uiwriter/data/datasource.ods |binary
sw/qa/extras/uiwriter/uiwriter.cxx | 8 +++--
sw/source/filter/ww8/ww8atr.cxx | 43 +++++++++++++++++++++++++++++-
3 files changed, 47 insertions(+), 4 deletions(-)
New commits:
commit 2425c5cc08b150c9b1b9a6f542b2f5b46a695b40
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date: Wed Jan 17 12:41:41 2018 +0300
tdf#115013: quote columns with spaces and properly escape characters
Unit test updated
Change-Id: If36c90c0ff372ce45666674d2487e6edf2536dbf
Reviewed-on: https://gerrit.libreoffice.org/48038
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/48078
Reviewed-by: Aron Budea <aron.budea at collabora.com>
Tested-by: Aron Budea <aron.budea at collabora.com>
diff --git a/sw/qa/extras/uiwriter/data/datasource.ods b/sw/qa/extras/uiwriter/data/datasource.ods
index 076659679575..81d78440656e 100644
Binary files a/sw/qa/extras/uiwriter/data/datasource.ods and b/sw/qa/extras/uiwriter/data/datasource.ods differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 6a065e712bea..5c96aacf7a1e 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -4647,7 +4647,9 @@ void SwUiWriterTest::testTdf104492()
void SwUiWriterTest::testTdf115013()
{
- //create new writer document
+ const OUString sColumnName("Name with spaces, \"quotes\" and \\backslashes");
+
+ //create new writer document
SwDoc* pDoc = createDoc();
{
@@ -4663,7 +4665,7 @@ void SwUiWriterTest::testTdf115013()
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
SwDBFieldType* pFieldType = static_cast<SwDBFieldType*>(pWrtShell->InsertFieldType(
- SwDBFieldType(pDoc, "Name", aDBData)));
+ SwDBFieldType(pDoc, sColumnName, aDBData)));
CPPUNIT_ASSERT(pFieldType);
// Insert the field into document
@@ -4686,7 +4688,7 @@ void SwUiWriterTest::testTdf115013()
CPPUNIT_ASSERT(pField);
OUString sColumn = static_cast<SwDBFieldType*>(pField->GetTyp())->GetColumnName();
// The column name must come correct after round trip
- CPPUNIT_ASSERT_EQUAL(OUString("Name"), sColumn);
+ CPPUNIT_ASSERT_EQUAL(sColumnName, sColumn);
}
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index abb637f923a4..7e90c2a27029 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -2458,6 +2458,46 @@ void WW8AttributeOutput::WriteExpand( const SwField* pField )
SwWW8Writer::WriteString16( m_rWW8Export.Strm(), sExpand, false );
}
+namespace
+{
+// Escapes a token string for storing in Word formats. Its import counterpart
+// is lcl_ExtractToken in writerfilter/source/dmapper/DomainMapper_Impl.cxx
+OUString EscapeToken(const OUString& rCommand)
+{
+ bool bWasEscaped = false;
+
+ const int nBufferLen = rCommand.getLength()*1.5;
+ OUStringBuffer sResult(nBufferLen);
+ sResult.append('"'); // opening quote
+ for (sal_Int32 i = 0; i < rCommand.getLength(); ++i)
+ {
+ sal_Unicode ch = rCommand[i];
+ switch (ch)
+ {
+ case '\\':
+ case '"':
+ // Backslashes and doublequotes must be escaped
+ bWasEscaped = true;
+ sResult.append('\\');
+ break;
+ case ' ':
+ // Spaces require quotation
+ bWasEscaped = true;
+ break;
+ }
+ sResult.append(ch);
+ }
+
+ if (bWasEscaped)
+ {
+ sResult.append('"'); // closing quote
+ return sResult.makeStringAndClear();
+ }
+ // No escapement/quotation was required
+ return rCommand;
+}
+}
+
void AttributeOutputBase::TextField( const SwFormatField& rField )
{
const SwField* pField = rField.GetField();
@@ -2535,7 +2575,8 @@ void AttributeOutputBase::TextField( const SwFormatField& rField )
break;
case RES_DBFLD:
{
- OUString sStr = FieldString(ww::eMERGEFIELD) + static_cast<SwDBFieldType *>(pField->GetTyp())->GetColumnName() + " ";
+ OUString sStr = FieldString(ww::eMERGEFIELD)
+ + EscapeToken(static_cast<SwDBFieldType *>(pField->GetTyp())->GetColumnName()) + " ";
GetExport().OutputField(pField, ww::eMERGEFIELD, sStr);
}
break;
More information about the Libreoffice-commits
mailing list