sc/qa/unit/helper/csv_handler.hxx | 2 ++ sc/source/ui/docshell/impex.cxx | 4 ++++ 2 files changed, 6 insertions(+)
New commits: commit 749a312ea55eaa0c3dc352a0e8a1f32f8b6fd9cf Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu Jul 24 15:47:52 2025 +0200 Commit: Noel Grandin <noelgran...@gmail.com> CommitDate: Fri Jul 25 07:30:07 2025 +0200 tdf#167664 slow loading CSV with tokens ending in newline takes the load time from several minutes to several seconds Change-Id: Ie5bed51e4fd9ba45a94f446b2c3e02cd7661fbcc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188286 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/sc/qa/unit/helper/csv_handler.hxx b/sc/qa/unit/helper/csv_handler.hxx index 3cb43bead360..439bcee308e8 100644 --- a/sc/qa/unit/helper/csv_handler.hxx +++ b/sc/qa/unit/helper/csv_handler.hxx @@ -100,6 +100,8 @@ public: else if (meStringType == StringType::PureString) { OUString aCSVString(p, n, RTL_TEXTENCODING_UTF8); + if (aCSVString.endsWith(" ")) + aCSVString = aCSVString.copy(0, aCSVString.getLength()-1); OUString aString = mpDoc->GetString(mnCol, mnRow, mnTab); #if DEBUG_CSV_HANDLER diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index 6872b359b6ac..d35e192a4bf7 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -1678,6 +1678,10 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm ) bool bIsQuoted = false; p = ScImportExport::ScanNextFieldFromString( p, aCell, cStr, pSeps, bMerge, bIsQuoted, bOverflowCell, bRemoveSpace ); + // some dodgy CSVs have a trailing linefeed in each token, which will + // make the code think that we have a multi-line field, which will slow things down a lot. + if (aCell.endsWith(" ")) + aCell = aCell.copy(0, aCell.getLength()-1); sal_uInt8 nFmt = SC_COL_STANDARD; for ( i=nInfoStart; i<nInfoCount; i++ )