tdf#156105 sw: trust SvxNumberFormat GetPrefix/GetSuffix
After LO 7.4 (backported to 7.2.5) created this
function that manually identifies the Prefix/Suffix,
there was some work done to ensure
GetPrefix and GetSuffix were trustworthy in
LO 7.5's commit 835cda561217bd8c53af2de927158dd5712b06c0
Author: Justin Luth on Tue Aug 2 13:30:31 2022 -0400
related tdf#150197: use SetListFormat or SetPrefix/Suffix
GetListFormat DEPENDS on having managed prefix/suffix itself...
So, lets make sure we use and fix these functions in only one place.
make CppunitTest_sw_ooxmlexport21 \
CPPUNIT_TEST_NAME=testTdf156105_percentSuffix
Change-Id: I44c021a200ba45960e39983087c6af268751fbc1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167792
Reviewed-by: Justin Luth <jluth@mail.com>
Reviewed-by: Vasily Melenchuk <vasily.melenchuk@cib.de>
Tested-by: Jenkins
diff --git a/sw/qa/extras/ooxmlexport/data/tdf156105_percentSuffix.odt b/sw/qa/extras/ooxmlexport/data/tdf156105_percentSuffix.odt
new file mode 100644
index 0000000..a5319f7
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf156105_percentSuffix.odt
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
index 01c42d0..6cfbe8d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
@@ -293,6 +293,13 @@ DECLARE_OOXMLEXPORT_TEST(testTdf158597, "tdf158597.docx")
}
}
DECLARE_OOXMLEXPORT_TEST(testTdf156105_percentSuffix, "tdf156105_percentSuffix.odt")
{
// given a numbered list with a non-escaping percent symbol in the prefix and suffix
CPPUNIT_ASSERT_EQUAL(OUString("(%)[%]"),
getProperty<OUString>(getParagraph(3), "ListLabelString"));
}
DECLARE_OOXMLEXPORT_TEST(testTdf160049_anchorMarginVML, "tdf160049_anchorMarginVML.docx")
{
// given a VML (Word 2003) document with a LEFT "column/text" anchored image
diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx
index c92d2af..f43ab14 100644
--- a/sw/source/core/doc/number.cxx
+++ b/sw/source/core/doc/number.cxx
@@ -721,32 +721,15 @@ OUString SwNumRule::MakeNumString( const SwNumberTree::tNumberVector & rNumVecto
if (rMyNFormat.GetNumberingType() == SVX_NUM_NUMBER_NONE)
{
if (!rMyNFormat.HasListFormat()) {
OUString sRet = bInclStrings ? rMyNFormat.GetPrefix() + rMyNFormat.GetSuffix() : OUString();
// since numbering is disabled for this level,
// only emit prefix/suffix (unless they are not wanted either)
if (!bInclStrings)
return OUString();
OUString sRet = rMyNFormat.GetPrefix() + rMyNFormat.GetSuffix();
if (bHideNonNumerical)
StripNonDelimiter(sRet);
return sRet;
}
// If numbering is disabled for this level we should emit just prefix/suffix
// Remove everything between first %1% and last %n% (including markers)
OUString sLevelFormat = rMyNFormat.GetListFormat(bInclStrings && !bHideNonNumerical);
if (bInclStrings && bHideNonNumerical) {
// If hiding non numerical text, we need to strip the prefix and suffix properly, so let's add them manually
OUString sPrefix = rMyNFormat.GetPrefix();
OUString sSuffix = rMyNFormat.GetSuffix();
StripNonDelimiter(sPrefix);
StripNonDelimiter(sSuffix);
sLevelFormat = sPrefix + sLevelFormat + sSuffix;
}
sal_Int32 nFirstPosition = sLevelFormat.indexOf("%");
sal_Int32 nLastPosition = sLevelFormat.lastIndexOf("%");
if (nFirstPosition >= 0 && nLastPosition >= nFirstPosition)
sLevelFormat = sLevelFormat.replaceAt(nFirstPosition, nLastPosition - nFirstPosition + 1, u"");
return sLevelFormat;
return sRet;
}
css::lang::Locale aLocale( LanguageTag::convertToLocale(nLang));