sc/qa/unit/data/fods/lostRowStyle.fods | 25 +++++++++++++++++++++++++ sc/qa/unit/subsequent_export_test4.cxx | 23 +++++++++++++++++++++++ sc/source/filter/xml/XMLStylesExportHelper.cxx | 2 +- 3 files changed, 49 insertions(+), 1 deletion(-)
New commits: commit adeb79b7bd4f492b46a97f8680a9b175fac79433 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Jun 11 16:15:46 2025 +0500 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Jun 11 22:29:57 2025 +0200 tdf#166939: Fix error in commit 36c41573ec7e47bd8c2b0f78210319c96088f164 The order of arguments of std::distance is the opposite. Change-Id: Ia125f071449f0bba4375204413736267cee5f57d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186370 Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Tested-by: Jenkins (cherry picked from commit 1ba380bc625f6a846b80bfdf2e2678788df49447) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186376 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sc/qa/unit/data/fods/lostRowStyle.fods b/sc/qa/unit/data/fods/lostRowStyle.fods new file mode 100644 index 000000000000..0ac7e64c7d80 --- /dev/null +++ b/sc/qa/unit/data/fods/lostRowStyle.fods @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" office:version="1.4" office:mimetype="application/vnd.oasis.opendocument.spreadsheet"> + <office:automatic-styles> + <style:style style:name="r_1" style:family="table-row"> + <style:table-row-properties style:row-height="1cm"/> + </style:style> + <style:style style:name="r_2" style:family="table-row"> + <style:table-row-properties style:row-height="2cm"/> + </style:style> + </office:automatic-styles> + <office:body> + <office:spreadsheet> + <table:table table:name="Sheet1"> + <table:table-column/> + <table:table-row table:style-name="r_1"> + <table:table-cell office:value-type="string" office:string-value="A1"/> + </table:table-row> + <table:table-row table:style-name="r_2"> + <table:table-cell office:value-type="string" office:string-value="A2"/> + </table:table-row> + </table:table> + </office:spreadsheet> + </office:body> +</office:document> \ No newline at end of file diff --git a/sc/qa/unit/subsequent_export_test4.cxx b/sc/qa/unit/subsequent_export_test4.cxx index 491743a6c87f..2bd47c95359a 100644 --- a/sc/qa/unit/subsequent_export_test4.cxx +++ b/sc/qa/unit/subsequent_export_test4.cxx @@ -2274,6 +2274,29 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, testTdf166939) assertXPath(pXmlDoc, "//office:automatic-styles/style:style[@style:name='a']", 1); } +CPPUNIT_TEST_FIXTURE(ScExportTest4, testTdf166939_1) +{ + // Check that the autostyles are stored correctly, when autostyle names are not standard (are + // not like "ro1"; the chosen names are "r_1", "r_2"). A mistake had made a function return + // existing style's index negative, and that wasn't caught in tests... + loadWithParams(createFileURL(u"fods/lostRowStyle.fods"), + { comphelper::makePropertyValue(u"AsTemplate"_ustr, true) }); + // Saving it must keep the autostyles + save(u"calc8"_ustr); + xmlDocUniquePtr pXmlDoc = parseExport(u"content.xml"_ustr); + CPPUNIT_ASSERT(pXmlDoc); + assertXPath( + pXmlDoc, + "//office:automatic-styles/style:style[@style:family='table-row'][@style:name='r_1']", 1); + assertXPath( + pXmlDoc, + "//office:automatic-styles/style:style[@style:family='table-row'][@style:name='r_2']", 1); + assertXPath(pXmlDoc, "//table:table/table:table-row[1]", "style-name", u"r_1"); + // When the bug was introduced, this failed with + // - In <>, XPath '//table:table/table:table-row[2]' no attribute 'style-name' exist + assertXPath(pXmlDoc, "//table:table/table:table-row[2]", "style-name", u"r_2"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/xml/XMLStylesExportHelper.cxx b/sc/source/filter/xml/XMLStylesExportHelper.cxx index 1203e660465c..b6d0a510419d 100644 --- a/sc/source/filter/xml/XMLStylesExportHelper.cxx +++ b/sc/source/filter/xml/XMLStylesExportHelper.cxx @@ -916,7 +916,7 @@ sal_Int32 ScColumnRowStylesBase::GetIndexOfStyleName(std::u16string_view rString } if (auto i = std::find(aStyleNames.begin(), aStyleNames.end(), rString); i != aStyleNames.end()) - return std::distance(i, aStyleNames.begin()); + return std::distance(aStyleNames.begin(), i); return -1; }