sw/qa/extras/ooxmlexport/data/invalid_date_form_field.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport11.cxx | 80 +++++++++++++ writerfilter/source/dmapper/DomainMapper.cxx | 17 +- 3 files changed, 91 insertions(+), 6 deletions(-)
New commits: commit 488300022535ba4874b1f810a519d78e48835207 Author: Tamás Zolnai <[email protected]> AuthorDate: Fri Jul 12 19:37:40 2019 +0200 Commit: Andras Timar <[email protected]> CommitDate: Sun Jul 14 00:17:37 2019 +0200 MSForms: DOCX filter: import manually set date field as plain text In MSO the user can add any text in the date field without having it in the specified date format. We import this kind of date as plain text. Reviewed-on: https://gerrit.libreoffice.org/75452 Tested-by: Jenkins Reviewed-by: Tamás Zolnai <[email protected]> (cherry picked from commit 52205f85582aaaee04fcfffd1c1729454f512400) Change-Id: Ied4bf03a3ac4c9b6f1cfc78d91e6a52ad3d6e179 Reviewed-on: https://gerrit.libreoffice.org/75545 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Andras Timar <[email protected]> diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index d40a33084f7e..ae345de6e0fb 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -1049,10 +1049,7 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) m_pImpl->m_pSdtHelper->getDropDownItems().push_back(sStringValue); break; case NS_ooxml::LN_CT_SdtDate_fullDate: - if (!IsInHeaderFooter()) - m_pImpl->m_pSdtHelper->getDate().append(sStringValue); - else - m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "ooxml:CT_SdtDate_fullDate", sStringValue); + m_pImpl->m_pSdtHelper->getDate().append(sStringValue); break; case NS_ooxml::LN_CT_Background_color: if (m_pImpl->GetSettingsTable()->GetDisplayBackgroundShape()) @@ -3356,8 +3353,16 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len) // Form controls are not allowed in headers / footers; see sw::DocumentContentOperationsManager::InsertDrawObj() else if (!m_pImpl->m_pSdtHelper->getDateFormat().isEmpty() && !IsInHeaderFooter()) { - // date field is imported, we don't need the corresponding date text - return; + // Date field will be imported, so we don't need the corresponding date text in most of the cases + // however when fullDate is not specified, but we have a date string we need to import it as + // simple text (this is the case when user sets date field manually in MSO). + if(!m_pImpl->m_pSdtHelper->getDate().toString().isEmpty() || sText.isEmpty()) + { + return; + } + // Remove date field attributes to avoid to import an actual date field + m_pImpl->m_pSdtHelper->getDateFormat().truncate(); + m_pImpl->m_pSdtHelper->getLocale().truncate(); } else if (!m_pImpl->m_pSdtHelper->isInteropGrabBagEmpty()) { commit 85badfd7032daeda15a0c8835b1af2d764a17952 Author: Tamás Zolnai <[email protected]> AuthorDate: Mon Jul 1 14:51:38 2019 +0200 Commit: Andras Timar <[email protected]> CommitDate: Sun Jul 14 00:17:25 2019 +0200 MSForms: DOCX filter: add a test case about invalid date form fields Reviewed-on: https://gerrit.libreoffice.org/75451 Tested-by: Jenkins Reviewed-by: Tamás Zolnai <[email protected]> (cherry picked from commit 2f4ccb1d5ea4258da42f2f6a0b62161399e13bcc) Change-Id: I2048198d81ea4abf58b2b499b89495cd51b5c7ff Reviewed-on: https://gerrit.libreoffice.org/75544 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Andras Timar <[email protected]> diff --git a/sw/qa/extras/ooxmlexport/data/invalid_date_form_field.docx b/sw/qa/extras/ooxmlexport/data/invalid_date_form_field.docx new file mode 100644 index 000000000000..9dc24e768b0f Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/invalid_date_form_field.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx index f77320436ea3..dd045978f4b1 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx @@ -26,6 +26,9 @@ #include <sfx2/docfile.hxx> #include <sfx2/docfilt.hxx> #include <svx/xfillit0.hxx> +#include <xmloff/odffields.hxx> +#include <IDocumentMarkAccess.hxx> +#include <IMark.hxx> class Test : public SwModelTestBase { @@ -468,6 +471,83 @@ DECLARE_OOXMLEXPORT_TEST(testImageCommentAtChar, "image-comment-at-char.docx") } +DECLARE_OOXMLIMPORT_TEST(testInvalidDateFormField, "invalid_date_form_field.docx") +{ + + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); + IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(6), pMarkAccess->getAllMarksCount()); + + int nIndex = 0; + for(auto aIter = pMarkAccess->getAllMarksBegin(); aIter != pMarkAccess->getAllMarksEnd(); ++aIter) + { + ::sw::mark::IFieldmark* pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(aIter->get()); + + if(!pFieldmark) + continue; + + CPPUNIT_ASSERT(pFieldmark); + CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname()); + + // Check date field's parameters. + const sw::mark::IFieldmark::parameter_map_t* const pParameters = pFieldmark->GetParameters(); + OUString sDateFormat; + auto pResult = pParameters->find(ODF_FORMDATE_DATEFORMAT); + if (pResult != pParameters->end()) + { + pResult->second >>= sDateFormat; + } + + OUString sLang; + pResult = pParameters->find(ODF_FORMDATE_DATEFORMAT_LANGUAGE); + if (pResult != pParameters->end()) + { + pResult->second >>= sLang; + } + + OUString sCurrentDate; + pResult = pParameters->find(ODF_FORMDATE_CURRENTDATE); + if (pResult != pParameters->end()) + { + pResult->second >>= sCurrentDate; + } + + // The first one has invalid date format (invalid = LO can't parse it) + if(nIndex == 0) + { + + CPPUNIT_ASSERT_EQUAL(OUString("YYYY.MM.DDT00:00:00Z"), sDateFormat); + CPPUNIT_ASSERT_EQUAL(OUString("en-US"), sLang); + CPPUNIT_ASSERT_EQUAL(OUString(""), sCurrentDate); + + CPPUNIT_ASSERT_EQUAL(sal_uLong(9), pFieldmark->GetMarkStart().nNode.GetIndex()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), pFieldmark->GetMarkStart().nContent.GetIndex()); + } + else if (nIndex == 1) // The second has wrong date + { + CPPUNIT_ASSERT_EQUAL(OUString("MM/DD/YY"), sDateFormat); + CPPUNIT_ASSERT_EQUAL(OUString("en-US"), sLang); + CPPUNIT_ASSERT_EQUAL(OUString("2019.06.34"), sCurrentDate); + + CPPUNIT_ASSERT_EQUAL(sal_uLong(9), pFieldmark->GetMarkStart().nNode.GetIndex()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(13), pFieldmark->GetMarkStart().nContent.GetIndex()); + } + else // The third one has wrong local + { + CPPUNIT_ASSERT_EQUAL(OUString("[NatNum12 MMMM=abbreviation]YYYY\". \"MMMM D."), sDateFormat); + CPPUNIT_ASSERT_EQUAL(OUString("xxxx"), sLang); + CPPUNIT_ASSERT_EQUAL(OUString("2019.06.11"), sCurrentDate); + + CPPUNIT_ASSERT_EQUAL(sal_uLong(9), pFieldmark->GetMarkStart().nNode.GetIndex()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(23), pFieldmark->GetMarkStart().nContent.GetIndex()); + } + ++nIndex; + } + CPPUNIT_ASSERT_EQUAL(int(3), nIndex); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
