diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index b72f05ebe..f590c0cd9 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 53374 - Avoid exceptions when parsing hyperlinks of type "javascript://" 53404 - Fixed compatibility bug with modifying xls files created by POI-3.6 and earlier 53979 - Support fetching properties of Numbered Lists from PPT files 53784 - Partial HSMF support for fixed sized properties diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java index be13cf0f0..37fdc5a58 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java @@ -21,6 +21,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.nio.ByteBuffer; import java.io.UnsupportedEncodingException; +import java.util.regex.Pattern; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidOperationException; @@ -147,6 +148,8 @@ public final class PackagingURIHelper { PACKAGE_ROOT_PART_NAME = tmpPACKAGE_ROOT_PART_NAME; } + private static final Pattern missingAuthPattern = Pattern.compile("\\w+://"); + /** * Gets the URI for the package root. * @@ -706,6 +709,9 @@ public final class PackagingURIHelper { value = path + "#" + encode(fragment); } + if(missingAuthPattern.matcher(value).matches()){ + value += "/"; + } return new URI(value); } diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java index 24d19a931..39ab5ed4d 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java @@ -123,7 +123,8 @@ public class TestPackagingURIHelper extends TestCase { "..\\Program%20Files\\AGEIA%20Technologies\\v2.3.3\\NxCooking.dll", "file:///D:\\seva\\1981\\r810102ns.mp3", "..\\cygwin\\home\\yegor\\dinom\\%5baccess%5d.2010-10-26.log", - "#'Instructions (Text)'!B21" + "#'Instructions (Text)'!B21", + "javascript://" }; for(String s : href){ try { @@ -134,4 +135,11 @@ public class TestPackagingURIHelper extends TestCase { } } + public void test53734() throws Exception { + URI uri = PackagingURIHelper.toURI("javascript://"); + // POI appends a trailing slash tpo avoid "Expected authority at index 13: javascript://" + // https://issues.apache.org/bugzilla/show_bug.cgi?id=53734 + assertEquals("javascript:///", uri.toASCIIString()); + } + } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java index cf51b40d8..9a79bf3cc 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java @@ -243,4 +243,13 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink { assertEquals("B1", l2.getCellRef()); } + public void test53734() { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("53734.xlsx"); + XSSFHyperlink link = wb.getSheetAt(0).getRow(0).getCell(0).getHyperlink(); + assertEquals("javascript:///", link.getAddress()); + + wb = XSSFTestDataSamples.writeOutAndReadBack(wb); + link = wb.getSheetAt(0).getRow(0).getCell(0).getHyperlink(); + assertEquals("javascript:///", link.getAddress()); + } } diff --git a/test-data/spreadsheet/53734.xlsx b/test-data/spreadsheet/53734.xlsx new file mode 100644 index 000000000..58aa49913 Binary files /dev/null and b/test-data/spreadsheet/53734.xlsx differ