[Libreoffice-commits] core.git: Branch 'libreoffice-6-1' - 2 commits - basic/qa basic/source sw/qa writerfilter/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Sat Nov 17 16:52:10 UTC 2018
basic/qa/basic_coverage/test_mid_replace_less.vb | 19 ++++++++
basic/qa/basic_coverage/test_mid_replace_more.vb | 17 +++++++
basic/qa/basic_coverage/test_mid_replace_more_end.vb | 19 ++++++++
basic/source/runtime/methods.cxx | 14 ++----
sw/qa/extras/ooxmlimport/data/tdf121203.docx |binary
sw/qa/extras/ooxmlimport/ooxmlimport2.cxx | 8 +++
writerfilter/source/dmapper/DomainMapper.cxx | 2
writerfilter/source/dmapper/SdtHelper.cxx | 41 ++++++++++++++++---
writerfilter/source/dmapper/SdtHelper.hxx | 4 +
9 files changed, 109 insertions(+), 15 deletions(-)
New commits:
commit 3478c3d40b06163816e15f63cf71892cfae9f868
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Nov 12 23:01:12 2018 +0100
Commit: Caolán McNamara <caolanm at redhat.com>
CommitDate: Sat Nov 17 17:51:58 2018 +0100
tdf#121203 DOCX import: fix loss of free-form text in date control
Date SDT from DOCX is imported as date control since commit
3ec2d26dc2017ac4a27483febfc63328632f352d (bnc#779630 initial DOCX import
of w:sdt's w:date, 2013-04-30).
One detail I missed there is our date control is strict: it doesn't
allow free-form text. However, DOCX date SDT has an optional ISO date,
but the actual value can be free-form text. This means that importing
free-form text without an ISO date is lost on import.
Fix the data loss by restricting the creation of the date control: only
do this if we recognize the date format or in case we have an ISO date.
Otherwise just show the free-form text to avoid data loss.
(cherry picked from commit 3583f7a1256c901199574c8373443038e28813f0)
Change-Id: I8125bdc749954a6a1c496de74b6682744adb7680
Reviewed-on: https://gerrit.libreoffice.org/63335
Tested-by: Jenkins
Tested-by: Xisco Faulí <xiscofauli at libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/sw/qa/extras/ooxmlimport/data/tdf121203.docx b/sw/qa/extras/ooxmlimport/data/tdf121203.docx
new file mode 100644
index 000000000000..5aa3b2ed7474
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/tdf121203.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
index 3de2c9bcb097..6b54a7991fb3 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
@@ -37,6 +37,14 @@ DECLARE_OOXMLIMPORT_TEST(testTdf108545_embeddedDocxIcon, "tdf108545_embeddedDocx
CPPUNIT_ASSERT_EQUAL(embed::Aspects::MSOLE_ICON, xSupplier->getAspect());
}
+DECLARE_OOXMLIMPORT_TEST(testTdf121203, "tdf121203.docx")
+{
+ // Make sure that the date SDT's content is imported as plain text, as it
+ // has no ISO date, so we have no idea how to represent that with our date
+ // control.
+ CPPUNIT_ASSERT_EQUAL(OUString("17-Oct-2018 09:00"), getRun(getParagraph(1), 1)->getString());
+}
+
DECLARE_OOXMLIMPORT_TEST(testTdf109053, "tdf109053.docx")
{
// Table was imported into a text frame which led to a one page document
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 07400a945856..b14db3d28767 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -3241,7 +3241,7 @@ 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())
+ else if (m_pImpl->m_pSdtHelper->validateDateFormat() && !IsInHeaderFooter())
{
/*
* Here we assume w:sdt only contains a single text token. We need to
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx
index b80903e44efa..8f15d51a963e 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -21,6 +21,26 @@
#include "DomainMapper_Impl.hxx"
#include "StyleSheetTable.hxx"
+namespace
+{
+/// Maps OOXML <w:dateFormat> values to UNO date format values.
+sal_Int16 getUNODateFormat(const OUString& rDateFormat)
+{
+ // See com/sun/star/awt/UnoControlDateFieldModel.idl, DateFormat; sadly
+ // there are no constants.
+ sal_Int16 nDateFormat = -1;
+
+ if (rDateFormat == "M/d/yyyy" || rDateFormat == "M.d.yyyy")
+ // MMDDYYYY
+ nDateFormat = 8;
+ else if (rDateFormat == "dd/MM/yyyy")
+ // DDMMYYYY
+ nDateFormat = 7;
+
+ return nDateFormat;
+}
+}
+
namespace writerfilter
{
namespace dmapper
@@ -89,6 +109,14 @@ void SdtHelper::createDropDownControl()
m_aDropDownItems.clear();
}
+bool SdtHelper::validateDateFormat()
+{
+ bool bRet = !m_sDate.isEmpty() || getUNODateFormat(m_sDateFormat.toString()) != -1;
+ if (!bRet)
+ m_sDateFormat.setLength(0);
+ return bRet;
+}
+
void SdtHelper::createDateControl(OUString const& rContentText, const beans::PropertyValue& rCharFormat)
{
uno::Reference<awt::XControlModel> xControlModel;
@@ -111,14 +139,17 @@ void SdtHelper::createDateControl(OUString const& rContentText, const beans::Pro
xPropertySet->setPropertyValue("Dropdown", uno::makeAny(true));
// See com/sun/star/awt/UnoControlDateFieldModel.idl, DateFormat; sadly there are no constants
- sal_Int16 nDateFormat = 0;
OUString sDateFormat = m_sDateFormat.makeStringAndClear();
- if (sDateFormat == "M/d/yyyy" || sDateFormat == "M.d.yyyy")
- // Approximate with MM.dd.yyy
- nDateFormat = 8;
- else
+ sal_Int16 nDateFormat = getUNODateFormat(sDateFormat);
+ if (nDateFormat == -1)
+ {
// Set default format, so at least the date picker is created.
SAL_WARN("writerfilter", "unhandled w:dateFormat value");
+ if (m_sDate.isEmpty())
+ return;
+ else
+ nDateFormat = 0;
+ }
xPropertySet->setPropertyValue("DateFormat", uno::makeAny(nDateFormat));
util::Date aDate;
diff --git a/writerfilter/source/dmapper/SdtHelper.hxx b/writerfilter/source/dmapper/SdtHelper.hxx
index 2d9309adee49..e2a69fbb667c 100644
--- a/writerfilter/source/dmapper/SdtHelper.hxx
+++ b/writerfilter/source/dmapper/SdtHelper.hxx
@@ -86,6 +86,10 @@ public:
{
return m_sDateFormat;
}
+
+ /// Decides if we have enough information to create a date control.
+ bool validateDateFormat();
+
OUStringBuffer& getLocale()
{
return m_sLocale;
commit cb2cd5b76b0981bf07b8d1264f4b3074543a19eb
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Tue Nov 13 13:05:01 2018 +0100
Commit: Caolán McNamara <caolanm at redhat.com>
CommitDate: Sat Nov 17 17:51:43 2018 +0100
tdf#121325: Replace all of given length, even if replacement is shorter
Both LO and MS Basic restrict the amount of replacement text ("If the Length
parameter in the <emph>Mid statement</emph> is less than the length of the text
that you want to replace, the text is reduced to the specified length." in
helpcontent2/source/text/sbasic/shared/03120306.xhp, resp. "The number of
characters replaced is always less than or equal to the number of characters in
Target." at <https://docs.microsoft.com/en-us/dotnet/visual-basic/
language-reference/statements/mid-statement>).
But cc20344010e94eda22fee662aab966d395a0796a "tdf#111313: Honor bWriteNoLenParam
in !bCompatibility, too" had introduced a regression (in the non--compatibility-
mode case), restricting the amount of replaced text to be no more than the
amount of replacement text, even if the given length argument was larger.
(Which had already regressed in the past, see
<https://bugs.documentfoundation.org/show_bug.cgi?id=62090> "Mid statement
doesn't work as expected".)
Added test cases now.
Change-Id: I21d4409f49a2437eb0e1a1e200561d803c42a24c
Reviewed-on: https://gerrit.libreoffice.org/63328
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
(cherry picked from commit a6a48eeef16e473be14642469cd922f177f54998)
Reviewed-on: https://gerrit.libreoffice.org/63332
Tested-by: Xisco Faulí <xiscofauli at libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/basic/qa/basic_coverage/test_mid_replace_less.vb b/basic/qa/basic_coverage/test_mid_replace_less.vb
new file mode 100644
index 000000000000..27a02382c3fd
--- /dev/null
+++ b/basic/qa/basic_coverage/test_mid_replace_less.vb
@@ -0,0 +1,19 @@
+'
+' This file is part of the LibreOffice project.
+'
+' This Source Code Form is subject to the terms of the Mozilla Public
+' License, v. 2.0. If a copy of the MPL was not distributed with this
+' file, You can obtain one at http://mozilla.org/MPL/2.0/.
+'
+
+' cf. <https://bugs.documentfoundation.org/show_bug.cgi?id=62090> "Mid statement doesn't work as
+' expected":
+Function doUnitTest as Integer
+ s = "The lightbrown fox"
+ Mid(s, 5, 10, "lazy")
+ If (s = "The lazy fox") Then
+ doUnitTest = 1
+ Else
+ doUnitTest = 0
+ End If
+End Function
diff --git a/basic/qa/basic_coverage/test_mid_replace_more.vb b/basic/qa/basic_coverage/test_mid_replace_more.vb
new file mode 100644
index 000000000000..c6d75ca90245
--- /dev/null
+++ b/basic/qa/basic_coverage/test_mid_replace_more.vb
@@ -0,0 +1,17 @@
+'
+' This file is part of the LibreOffice project.
+'
+' This Source Code Form is subject to the terms of the Mozilla Public
+' License, v. 2.0. If a copy of the MPL was not distributed with this
+' file, You can obtain one at http://mozilla.org/MPL/2.0/.
+'
+
+Function doUnitTest as Integer
+ s = "The fox jumps"
+ Mid(s, 5, 3, "duck")
+ If (s = "The duc jumps") Then
+ doUnitTest = 1
+ Else
+ doUnitTest = 0
+ End If
+End Function
diff --git a/basic/qa/basic_coverage/test_mid_replace_more_end.vb b/basic/qa/basic_coverage/test_mid_replace_more_end.vb
new file mode 100644
index 000000000000..c5d26a46a8db
--- /dev/null
+++ b/basic/qa/basic_coverage/test_mid_replace_more_end.vb
@@ -0,0 +1,19 @@
+'
+' This file is part of the LibreOffice project.
+'
+' This Source Code Form is subject to the terms of the Mozilla Public
+' License, v. 2.0. If a copy of the MPL was not distributed with this
+' file, You can obtain one at http://mozilla.org/MPL/2.0/.
+'
+
+' cf. examples at <https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/
+' statements/mid-statement>:
+Function doUnitTest as Integer
+ s = "The fox jumps"
+ Mid(s, 5, 100, "cow jumped over")
+ If (s = "The cow jumpe") Then
+ doUnitTest = 1
+ Else
+ doUnitTest = 0
+ End If
+End Function
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 589105ff3935..a980e19b48b3 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -1155,26 +1155,22 @@ void SbRtl_Mid(StarBASIC *, SbxArray & rPar, bool bWrite)
sal_Int32 nReplaceLen;
if( bWriteNoLenParam )
{
- nReplaceLen = nReplaceStrLen;
+ nReplaceLen = nArgLen - nStartPos;
}
else
{
nReplaceLen = nLen;
- if( nReplaceLen < 0 || nReplaceLen > nReplaceStrLen )
+ if( nReplaceLen < 0 || nReplaceLen > nArgLen - nStartPos )
{
- nReplaceLen = nReplaceStrLen;
+ nReplaceLen = nArgLen - nStartPos;
}
}
- sal_Int32 nReplaceEndPos = nStartPos + nReplaceLen;
- if( nReplaceEndPos > nArgLen )
- {
- nReplaceLen -= (nReplaceEndPos - nArgLen);
- }
OUStringBuffer aResultStr = aArgStr;
sal_Int32 nErase = nReplaceLen;
aResultStr.remove( nStartPos, nErase );
- aResultStr.insert( nStartPos, aReplaceStr.getStr(), nReplaceLen);
+ aResultStr.insert(
+ nStartPos, aReplaceStr.getStr(), std::min(nReplaceLen, nReplaceStrLen));
rPar.Get(1)->PutString( aResultStr.makeStringAndClear() );
}
More information about the Libreoffice-commits
mailing list