]> source.dussan.org Git - poi.git/commitdiff
Bug #53374 Avoid exceptions when parsing hyperlinks of type 'javascript://'
authorYegor Kozlov <yegor@apache.org>
Fri, 26 Oct 2012 11:38:28 +0000 (11:38 +0000)
committerYegor Kozlov <yegor@apache.org>
Fri, 26 Oct 2012 11:38:28 +0000 (11:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1402470 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java
test-data/spreadsheet/53734.xlsx [new file with mode: 0644]

index b72f05ebeb8fede5c50b7dac980d89063c467016..f590c0cd9b808fe486b5ed40aaf18af78e87e68d 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.9-beta1" date="2012-??-??">
+          <action dev="poi-developers" type="add">53374 - Avoid exceptions when parsing hyperlinks of type "javascript://"</action>
           <action dev="poi-developers" type="add">53404 - Fixed compatibility bug with modifying xls files created by POI-3.6 and earlier</action>
           <action dev="poi-developers" type="add">53979 - Support fetching properties of Numbered Lists from PPT files</action>
           <action dev="poi-developers" type="add">53784 - Partial HSMF support for fixed sized properties</action>
index be13cf0f05eaeca63dad87f1ff82728635b62b48..37fdc5a58b1a7bb0e75a8945d95fbaed305596a2 100644 (file)
@@ -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);
     }
 
index 24d19a931f3b1c384c5407141aa564af64f1691c..39ab5ed4d34fabbef931534fdfd249dfda218980 100644 (file)
@@ -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());
+    }
+
 }
index cf51b40d86aea4bb82d727f265bd4abcb600d8ad..9a79bf3cca048d5c19e70aba964bf201b4c4a337 100644 (file)
@@ -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 (file)
index 0000000..58aa499
Binary files /dev/null and b/test-data/spreadsheet/53734.xlsx differ