aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-07-20 17:00:32 +0000
committerPJ Fanning <fanningpj@apache.org>2021-07-20 17:00:32 +0000
commitcb6e6e0609a99c15a656ba850b122cea83234870 (patch)
treea444215b3bb4fc1fe233722322a2ed078e3c2e40
parentc0c39ed7793ab7ffe803c838a19f918dca80f9c7 (diff)
downloadpoi-cb6e6e0609a99c15a656ba850b122cea83234870.tar.gz
poi-cb6e6e0609a99c15a656ba850b122cea83234870.zip
[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
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackagePartCollection.java2
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackagePartCollection.java45
-rw-r--r--test-data/openxml4j/64473.xlsxbin0 -> 12044 bytes
3 files changed, 46 insertions, 1 deletions
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<PackagePart> allParts = pkg.getParts();
+ assertEquals(15, allParts.size());
+ List<PackagePart> 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 0000000000..a20756d692
--- /dev/null
+++ b/test-data/openxml4j/64473.xlsx
Binary files differ