From: Simon Steiner Date: Wed, 19 Jan 2022 09:53:53 +0000 (+0000) Subject: FOP-2839: Links to pdf files with no scheme should open in pdf viewer X-Git-Tag: fop-2_8~2^2~57 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bbd7343ba13043f8f78e175363037f052d648395;p=xmlgraphics-fop.git FOP-2839: Links to pdf files with no scheme should open in pdf viewer git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1897193 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java b/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java index 57f8a17a9..f0456a53f 100644 --- a/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java +++ b/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java @@ -589,6 +589,9 @@ public class PDFFactory { if (filename == null) { filename = uri.getSchemeSpecificPart(); } + if (scheme == null && filename.toLowerCase().endsWith(".pdf")) { + scheme = "file"; + } if (scheme == null) { return new PDFUri(uri.toASCIIString()); } else if (scheme.equalsIgnoreCase("embedded-file")) { diff --git a/fop-core/src/test/java/org/apache/fop/pdf/PDFLinkTestCase.java b/fop-core/src/test/java/org/apache/fop/pdf/PDFLinkTestCase.java index b4c6a5239..988a14668 100644 --- a/fop-core/src/test/java/org/apache/fop/pdf/PDFLinkTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/pdf/PDFLinkTestCase.java @@ -123,12 +123,12 @@ public class PDFLinkTestCase { {"/foo/bar 2.pdf", quote("<< /Type /Filespec /F (/foo/bar 2.pdf)")}, // PDF, Relative paths - {"foobar.pdf", quote("<< /URI (foobar.pdf)")}, //34 - {"foo bar.pdf", quote("<< /URI (foo%20bar.pdf)")}, - {"./foobar.pdf", quote("<< /URI (./foobar.pdf)")}, - {"./foo bar.pdf", quote("<< /URI (./foo%20bar.pdf)")}, - {"../foobar.pdf", quote("<< /URI (../foobar.pdf)")}, - {"../foo bar.pdf", quote("<< /URI (../foo%20bar.pdf)")}, + {"foobar.pdf", quote("<< /Type /Filespec /F (foobar.pdf)")}, //34 + {"foo bar.pdf", quote("<< /Type /Filespec /F (foo bar.pdf)")}, + {"./foobar.pdf", quote("<< /Type /Filespec /F (./foobar.pdf)")}, + {"./foo bar.pdf", quote("<< /Type /Filespec /F (./foo bar.pdf)")}, + {"../foobar.pdf", quote("<< /Type /Filespec /F (../foobar.pdf)")}, + {"../foo bar.pdf", quote("<< /Type /Filespec /F (../foo bar.pdf)")}, // PDF, Windows network paths {"\\\\foo\\bar.pdf", quote("<< /Type /Filespec /F (\\\\\\\\foo\\\\bar.pdf)")}, //40 @@ -165,12 +165,18 @@ public class PDFLinkTestCase { + quote("/D [ 2 /XYZ null null null ]")}, // PDF with fragments, Relative paths - {"foobar.pdf#dest=aa", quote("<< /URI (foobar.pdf#dest=aa)")}, //55 - {"foo bar.pdf#page=2", quote("<< /URI (foo%20bar.pdf#page=2)")}, - {"./foobar.pdf#dest=aa", quote("<< /URI (./foobar.pdf#dest=aa)")}, - {"./foo bar.pdf#page=2", quote("<< /URI (./foo%20bar.pdf#page=2)")}, - {"../foobar.pdf#dest=aa", quote("<< /URI (../foobar.pdf#dest=aa)")}, - {"../foo bar.pdf#page=2", quote("<< /URI (../foo%20bar.pdf#page=2)")}, + {"foobar.pdf#dest=aa", quote("<< /Type /Filespec /F (foobar.pdf)") + ".*" + quote("/S /GoToR") + ".*" + + quote("/D (aa)")}, //55 + {"foo bar.pdf#page=2", quote("<< /Type /Filespec /F (foo bar.pdf)") + ".*" + quote("/S /GoToR") + ".*" + + quote("/D [ 2 /XYZ null null null ]")}, + {"./foobar.pdf#dest=aa", quote("<< /Type /Filespec /F (./foobar.pdf)") + ".*" + quote("/S /GoToR") + + ".*" + quote("/D (aa)")}, + {"./foo bar.pdf#page=2", quote("<< /Type /Filespec /F (./foo bar.pdf)") + ".*" + quote("/S /GoToR") + ".*" + + quote("/D [ 2 /XYZ null null null ]")}, + {"../foobar.pdf#dest=aa", quote("<< /Type /Filespec /F (../foobar.pdf)") + ".*" + quote("/S /GoToR") + + ".*" + quote("/D (aa)")}, + {"../foo bar.pdf#page=2", quote("<< /Type /Filespec /F (../foo bar.pdf)") + ".*" + quote("/S /GoToR") + ".*" + + quote("/D [ 2 /XYZ null null null ]")}, // PDF with fragments, Windows network paths {"\\\\foo\\bar.pdf#dest=aa", quote("<< /Type /Filespec /F (\\\\\\\\foo\\\\bar.pdf)") + ".*" @@ -393,7 +399,7 @@ public class PDFLinkTestCase { {"file:examples.html", quote("<< /Type /Filespec /F (examples.html)")}, // parenthesis - {"simple_report_(version2.pdf", quote("<< /URI (simple_report_\\(version2.pdf)")} + {"simple_report_(version2.pdf", quote("<< /Type /Filespec /F (simple_report_\\(version2.pdf)")} }); } @@ -415,6 +421,6 @@ public class PDFLinkTestCase { Pattern r = Pattern.compile(expected); Matcher m = r.matcher(outString); - Assert.assertTrue(m.find()); + Assert.assertTrue(target + " " + outString, m.find()); } }