summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorAndreas Heinisch <andreas.heinisch@yahoo.de>2023-04-06 17:38:52 +0200
committerAndreas Heinisch <andreas.heinisch@yahoo.de>2023-04-07 14:00:42 +0200
commit40e3e9fd1c501cc1978d4370b6392701ccd42a71 (patch)
tree5c2cfb341f66d80085bb059bace278239050dfbb /sc
parent8bec0ff56c53e80be81a9f463fd1fd21ade33151 (diff)
tdf#113027 - Allow cycling cell reference types including whitespaces
A formula containing a remote reference to a sheet including a whitespace in its name does not correctly handle switching from relative to absolute cell references using the EXCEL R1C1 formular grammar. Change-Id: I3391f4e8f57993899b5e97f0a173b624b5ef0b22 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150109 Tested-by: Jenkins Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/unit/ucalc.cxx26
-rw-r--r--sc/source/core/tool/reffind.cxx4
2 files changed, 28 insertions, 2 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 8563ef8283c3..aa8dbc32b220 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -450,6 +450,32 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf66613)
m_pDoc->DeleteTab(nSecondTab);
}
+CPPUNIT_TEST_FIXTURE(Test, testTdf113027)
+{
+ // Insert some sheets including a whitespace in their name and switch the grammar to R1C1
+ CPPUNIT_ASSERT(m_pDoc->InsertTab(0, "Sheet 1"));
+ CPPUNIT_ASSERT(m_pDoc->InsertTab(1, "Sheet 2"));
+ FormulaGrammarSwitch aFGSwitch(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH_XL_R1C1);
+
+ // Add a formula containing a remote reference, i.e., to another sheet
+ const ScAddress aScAddress(0, 0, 0);
+ const OUString aFormula = "='Sheet 2'!RC";
+ m_pDoc->SetString(aScAddress, aFormula);
+
+ // Switch from relative to absolute cell reference
+ ScRefFinder aFinder(aFormula, aScAddress, *m_pDoc, m_pDoc->GetAddressConvention());
+ aFinder.ToggleRel(0, aFormula.getLength());
+
+ // Without the fix in place, this test would have failed with
+ // - Expected: ='Sheet 2'!R1C1
+ // - Actual : ='Sheet 2'!RC
+ // i.e. the cell reference was not changed from relative to absolute
+ CPPUNIT_ASSERT_EQUAL(OUString("='Sheet 2'!R1C1"), aFinder.GetText());
+
+ m_pDoc->DeleteTab(0);
+ m_pDoc->DeleteTab(1);
+}
+
CPPUNIT_TEST_FIXTURE(Test, testTdf90698)
{
CPPUNIT_ASSERT(m_pDoc->InsertTab (0, "Test"));
diff --git a/sc/source/core/tool/reffind.cxx b/sc/source/core/tool/reffind.cxx
index ab276196d399..ac080ae5a56e 100644
--- a/sc/source/core/tool/reffind.cxx
+++ b/sc/source/core/tool/reffind.cxx
@@ -91,7 +91,7 @@ sal_Int32 FindEndPosR1C1(const sal_Unicode* p, sal_Int32 nStartPos, sal_Int32 nE
if (*p == '\'')
{
// Skip until the closing quote.
- for (; nNewEnd <= nEndPos; ++p, ++nNewEnd)
+ for (++p; nNewEnd <= nEndPos; ++p, ++nNewEnd)
if (*p == '\'')
break;
if (nNewEnd > nEndPos)
@@ -100,7 +100,7 @@ sal_Int32 FindEndPosR1C1(const sal_Unicode* p, sal_Int32 nStartPos, sal_Int32 nE
else if (*p == '[')
{
// Skip until the closing bracket.
- for (; nNewEnd <= nEndPos; ++p, ++nNewEnd)
+ for (++p; nNewEnd <= nEndPos; ++p, ++nNewEnd)
if (*p == ']')
break;
if (nNewEnd > nEndPos)