You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/11/03 13:55:11 UTC
svn commit: r1894713 - in /poi/trunk/poi-ooxml/src:
main/java/org/apache/poi/xssf/usermodel/XSSFTable.java
test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java
Author: fanningpj
Date: Wed Nov 3 13:55:11 2021
New Revision: 1894713
URL: http://svn.apache.org/viewvc?rev=1894713&view=rev
Log:
[bug-65669] proper handling of apostrophe escaping in table column names
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTable.java
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java
Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTable.java?rev=1894713&r1=1894712&r2=1894713&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTable.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTable.java Wed Nov 3 13:55:11 2021
@@ -29,6 +29,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
+import org.apache.commons.collections4.map.CaseInsensitiveMap;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.ss.SpreadsheetVersion;
@@ -60,7 +61,7 @@ public class XSSFTable extends POIXMLDoc
private CTTable ctTable;
private transient List<XSSFXmlColumnPr> xmlColumnPrs;
private transient List<XSSFTableColumn> tableColumns;
- private transient HashMap<String, Integer> columnMap;
+ private transient CaseInsensitiveMap<String, Integer> columnMap;
private transient CellReference startCellReference;
private transient CellReference endCellReference;
private transient String commonXPath;
@@ -836,9 +837,8 @@ public class XSSFTable extends POIXMLDoc
public int findColumnIndex(String columnHeader) {
if (columnHeader == null) return -1;
if (columnMap == null) {
- // FIXME: replace with org.apache.commons.collections.map.CaseInsensitiveMap
final int count = getColumnCount();
- columnMap = new HashMap<>(count * 3 / 2);
+ columnMap = new CaseInsensitiveMap<>(count * 3 / 2);
int i = 0;
for (XSSFTableColumn column : getColumns()) {
@@ -849,7 +849,10 @@ public class XSSFTable extends POIXMLDoc
}
// Table column names with special characters need a single quote escape
// but the escape is not present in the column definition
- Integer idx = columnMap.get(caseInsensitive(columnHeader.replace("'", "")));
+ String unescapedString = columnHeader
+ .replace("''", "'")
+ .replace("'#", "#");
+ Integer idx = columnMap.get(unescapedString);
return idx == null ? -1 : idx;
}
Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java?rev=1894713&r1=1894712&r2=1894713&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java (original)
+++ poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFTable.java Wed Nov 3 13:55:11 2021
@@ -31,6 +31,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.util.AreaReference;
@@ -592,6 +593,49 @@ public final class TestXSSFTable {
}
}
+ @Test
+ void testBug65669() throws IOException {
+ String[] testValues = new String[] {"C'olumn", "Column"};
+ for (String testValue : testValues) {
+ try (XSSFWorkbook wb = new XSSFWorkbook()) {
+ XSSFSheet sheet = wb.createSheet();
+
+ final String column = testValue;
+
+ // Set the values for the table
+ XSSFRow row;
+ XSSFCell cell;
+ for (int i = 0; i < 3; i++) {
+ // Create row
+ row = sheet.createRow(i);
+ for (int j = 0; j < 3; j++) {
+ // Create cell
+ cell = row.createCell(j);
+ if (i == 0) {
+ final String columnName = column + (j + 1);
+ cell.setCellValue(columnName);
+ } else {
+ if (j != 2) {
+ cell.setCellValue((i + 1.0) * (j + 1.0));
+ }
+ }
+ }
+ }
+
+ // Create Table
+ AreaReference reference = wb.getCreationHelper().createAreaReference(
+ new CellReference(0, 0), new CellReference(2, 2));
+ XSSFTable table = sheet.createTable(reference);
+ table.setName("Table1");
+ table.setDisplayName("Table1");
+ for (int i = 1; i < 3; i++) {
+ cell = sheet.getRow(i).getCell(2);
+ cell.setCellFormula("Table1[[#This Row],[" + column + "1]]");
+ }
+ }
+ }
+ }
+
private static XSSFTable addTable(XSSFSheet sheet,int nRow, int nCol, int nNumRows, int nNumCols) {
for (int i = 0; i < nNumRows; i++) {
XSSFRow row = sheet.createRow(i + nRow);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org