From cb6e6e0609a99c15a656ba850b122cea83234870 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Tue, 20 Jul 2021 17:00:32 +0000 Subject: [PATCH] [bug-64473] OPCPackage.open(fileName, PackageAccess.READ) does not open valid xlsx file. Thanks to Yury Molchan. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1891692 13f79535-47bb-0310-9956-ffa450edef68 --- .../openxml4j/opc/PackagePartCollection.java | 2 +- .../opc/TestPackagePartCollection.java | 45 ++++++++++++++++++ test-data/openxml4j/64473.xlsx | Bin 0 -> 12044 bytes 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackagePartCollection.java create mode 100644 test-data/openxml4j/64473.xlsx diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackagePartCollection.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackagePartCollection.java index a5f3dfc258..c22fa1f68d 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackagePartCollection.java +++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackagePartCollection.java @@ -65,7 +65,7 @@ public final class PackagePartCollection implements Serializable { final String ppName = partName.getName(); final StringBuilder concatSeg = new StringBuilder(); // split at slash, but keep leading slash - final String delim = "(?=["+PackagingURIHelper.FORWARD_SLASH_STRING+".])"; + final String delim = "(?=["+PackagingURIHelper.FORWARD_SLASH_STRING+"])"; for (String seg : ppName.split(delim)) { concatSeg.append(seg); if (registerPartNameStr.contains(concatSeg.toString())) { diff --git a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackagePartCollection.java b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackagePartCollection.java new file mode 100644 index 0000000000..f64d582c12 --- /dev/null +++ b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackagePartCollection.java @@ -0,0 +1,45 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.openxml4j.opc; + +import static org.apache.poi.openxml4j.OpenXML4JTestDataSamples.openSampleStream; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.InputStream; +import java.util.List; +import java.util.regex.Pattern; + +import org.junit.jupiter.api.Test; + +public class TestPackagePartCollection { + + @Test + void testPackagePartCollection_64473() throws Exception { + InputStream is = openSampleStream("64473.xlsx"); + try (OPCPackage pkg = OPCPackage.open(is)) { + List allParts = pkg.getParts(); + assertEquals(15, allParts.size()); + List partsByName = pkg.getPartsByName(Pattern.compile("/xl/metadata.*")); + // contains the following parts: + // /xl/metadata + // /xl/metadata.xml + assertEquals(2, partsByName.size()); + } + } + +} diff --git a/test-data/openxml4j/64473.xlsx b/test-data/openxml4j/64473.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..a20756d69291394e20c66a631770d2cb8886515a GIT binary patch literal 12044 zcmeIYWmr`0`aV2#H%bbKfTVOQ4bt7+Idpf|Al-rpBHi5$0)o_lbR*r}{70X?Uwzom z{`h|S?R6Zp=9o3>I%n2>pI2Y)S%8C z;<5Abx9D34OxSx*it$8vY93m(ulzIZb_rcZ2aq*mSziPY%j~Oma1N{Yuya-i^s{iCdv$Md8fpePeoDKO`P${B~P;IGx{8Cbt(bp8HNg*0cat ze>$mQNdGC*TW?;Hwn-|{FMTgan8uxsk<7|Z=e%_L4HILVTFA$JwAXDGQ;=ZgcwFcn1Hbx&#>W?`$G*rec`#ianepdG&fgrh>fOuaN zfilMEI$1g>wTshZKmb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