From b1f9000485380c952ae7794316b3c10bab102a76 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Fri, 26 Oct 2012 11:38:28 +0000 Subject: [PATCH] Bug #53374 Avoid exceptions when parsing hyperlinks of type 'javascript://' git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1402470 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../poi/openxml4j/opc/PackagingURIHelper.java | 6 ++++++ .../openxml4j/opc/TestPackagingURIHelper.java | 10 +++++++++- .../poi/xssf/usermodel/TestXSSFHyperlink.java | 9 +++++++++ test-data/spreadsheet/53734.xlsx | Bin 0 -> 9409 bytes 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 test-data/spreadsheet/53734.xlsx diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index b72f05ebeb..f590c0cd9b 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 be13cf0f05..37fdc5a58b 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 24d19a931f..39ab5ed4d3 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 cf51b40d86..9a79bf3cca 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 0000000000000000000000000000000000000000..58aa49913d978c979551157a276945f7f6cfdb82 GIT binary patch literal 9409 zcmeHNRa6|?wrwD|ySr;}354JQ8f)C$-6aGF?(UvOLU4Bo!QCB#ga8481`QHkC->Z! zb2xc#ys!6jPkmI48r5rd?Y-ArYwop52?+BD2LJ~^0001#fS0yuc(zagz-w3l02_b+ ztt0MW?`mf6YM|=nXy&5F=4oe3k@pCi;WYpn^80^||KJ%INzwy$v*Uyu!QP7xmUA!C zg$=amT{#uQd`1r&-6cw)qomJV?zrT>5h<`ofqyYQv7L44lfZrC*k&!)5cFzkG2q-Q z*31xCRF{prZ+D%vR)dmXCre}jHnb7pCDYSKDY8LN12y&r%yL`{QdX6L;|H?gfn3SR z(NSka=3T?iY!(!7?W@rY+0lk3WICw4M8YDp_;lv6%-3y{h=y@ymziC2rG``9`9Q*O zRhIJW?F0u>ez!M7W%d2cU50tn;OuXUhRc^?I@omqwp8LTQ&5ei^L)>5Gqf_9{0jfEKqTAw^4x7-gii~lrc5(>|^bD|s<4ukg`77?jsHg7H zsh;}z(a3BMKpE;1zvrrSr+zWgoB}mtgOY?}0e@BE6Bc+lNy8tT!~mtR7OZDlx6({c zi2&*r=5AqITaBOEaqV_!BwuP%dHtkKa%g^%9^zm3_b>pZzmT+Ejh*@&@?E4l*TH zq1jGr1bA=w65(s1Z#9kF@(!Mlw|$IL6{19Pumy+Rx5Ukni^rGWW{3^T1md1%O=Aw; zP?^Bw&@JgIp4~U_J5d3{C#2U;h1McmM816SXUnxLzG@#6+9(S8C~taY)Y*%!YVcc@ ztRmhqKtod53=9B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