From d15286103648b5cbfadfc6eeec132f224b49e2ec Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 10 Aug 2023 09:38:39 +0000 Subject: [PATCH] [bug-66855] Formula parser incorrectly handles sheet name containing multiple single quotes in a row. Thanks to Kirill lebedev. This closes #496 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1911589 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/ss/formula/FormulaParser.java | 2 -- .../apache/poi/hssf/model/TestFormulaParser.java | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/poi/src/main/java/org/apache/poi/ss/formula/FormulaParser.java b/poi/src/main/java/org/apache/poi/ss/formula/FormulaParser.java index 83fe1051af..28d13bfbc8 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/FormulaParser.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/FormulaParser.java @@ -1182,8 +1182,6 @@ public final class FormulaParser { if (look == '\''){ // Any single quotes which were already present in the sheet name will be converted to double single quotes ('') // so switch back to single quote - sb.appendCodePoint(look); - nextChar(); break; } } diff --git a/poi/src/test/java/org/apache/poi/hssf/model/TestFormulaParser.java b/poi/src/test/java/org/apache/poi/hssf/model/TestFormulaParser.java index 2a3cb6c98c..40c96991bf 100644 --- a/poi/src/test/java/org/apache/poi/hssf/model/TestFormulaParser.java +++ b/poi/src/test/java/org/apache/poi/hssf/model/TestFormulaParser.java @@ -1371,6 +1371,22 @@ final class TestFormulaParser { wb.close(); } + @Test + void testParseSheetNameWithMultipleSingleQuotes() throws IOException { + try (HSSFWorkbook wb = new HSSFWorkbook()) { + wb.createSheet("Sh''t1"); + Ptg[] ptgs = parse("'Sh''''t1'!$A:$A,'Sh''''t1'!$1:$4", wb); + confirmTokenClasses(ptgs, + MemFuncPtg.class, + Area3DPtg.class, + Area3DPtg.class, + UnionPtg.class + ); + assertEquals(0, ((Area3DPtg)ptgs[1]).getExternSheetIndex()); + assertEquals(0, ((Area3DPtg)ptgs[2]).getExternSheetIndex()); + } + } + @Test void testExplicitRangeWithTwoSheetNames() throws IOException { HSSFWorkbook wb = new HSSFWorkbook();