diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-07-13 18:02:29 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-07-14 11:39:30 +0000 |
commit | a4fd1b2eafcc49486cb6a360d792f779659b68e2 (patch) | |
tree | 030b25510fa4160fd2231ba6890eb1bde8f0e9a7 | |
parent | 8cdf36a8e98e8dbbc9cad1a72c61e91d025171c9 (diff) |
fdo#80905 SwXTextFieldMasters::hasByName(): sync with SwXFieldMaster
Normally a mail merge field has a name like
"css.text.fieldmaster.DataBase.<datasource name>.<table name>.<column
name>", however this isn't enforced: just
"css.text.fieldmaster.DataBase.TEST" is also accepted (even if its
semantics are ~undefined).
If SwXFieldMaster::setPropertyValue() allows setting such a field master
name, then SwXTextFieldMasters::hasByName() should not ignore such field
masters that have no dot in their name ("TEST") or use "Database", not
"DataBase", otherwise (sane) client code in writerfilter ends up with
hasByName() returning false, but setPropertyValue() throwing an
exception, because the field master does have such a name.
This fixes DOCX/RTF import of multiple mail merge fields with the same
field command.
(cherry picked from commit d0a7a60cfa1a34ec7218656489b7463cd9eb1aad)
Conflicts:
sw/source/core/unocore/unofield.cxx
Change-Id: I498eabace25f8e466b3504ba13fa3060d4ba22da
Reviewed-on: https://gerrit.libreoffice.org/10269
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | sw/qa/extras/rtfimport/data/fdo80905.rtf | 12 | ||||
-rw-r--r-- | sw/qa/extras/rtfimport/rtfimport.cxx | 10 | ||||
-rw-r--r-- | sw/source/core/unocore/unofield.cxx | 4 |
3 files changed, 24 insertions, 2 deletions
diff --git a/sw/qa/extras/rtfimport/data/fdo80905.rtf b/sw/qa/extras/rtfimport/data/fdo80905.rtf new file mode 100644 index 000000000000..c088fe0e727d --- /dev/null +++ b/sw/qa/extras/rtfimport/data/fdo80905.rtf @@ -0,0 +1,12 @@ +{\rtf1 +\pard\plain +{\field +{\*\fldinst MERGEFIELD TEST \\* Upper \\* MERGEFORMAT} +{\fldrslt \'abTEST\'bb} +} +{\field +{\*\fldinst MERGEFIELD TEST \\* Upper \\* MERGEFORMAT} +{\fldrslt \'abTEST\'bb} +} +\par +} diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 4fd6941fce18..6f6dede53d68 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -1709,6 +1709,16 @@ DECLARE_RTFIMPORT_TEST(testFdo73241, "fdo73241.rtf") CPPUNIT_ASSERT_EQUAL(1, getPages()); } +DECLARE_RTFIMPORT_TEST(testFdo80905, "fdo80905.rtf") +{ + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + xFields->nextElement(); + // The problem was that there was only one field in the document, but there should be true. + CPPUNIT_ASSERT_EQUAL(true, static_cast<bool>(xFields->hasMoreElements())); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx index 30433534e4e3..56be0c0a8184 100644 --- a/sw/source/core/unocore/unofield.cxx +++ b/sw/source/core/unocore/unofield.cxx @@ -2674,11 +2674,11 @@ static sal_uInt16 lcl_GetIdByName( OUString& rName, OUString& rTypeName ) if( sUIName != sFldTypName ) rName = comphelper::string::setToken(rName, 1, '.', sUIName); } - else if (rTypeName == "DataBase") + else if (rTypeName.equalsIgnoreAsciiCase("DataBase")) { rName = rName.copy(RTL_CONSTASCII_LENGTH("DataBase.")); sal_uInt16 nDotCount = comphelper::string::getTokenCount(rName, '.'); - if( 2 <= nDotCount ) + if( 1 <= nDotCount ) { // #i51815# rName = "DataBase." + rName; |