[ 
https://issues.apache.org/jira/browse/FOP-3173?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17832839#comment-17832839
 ] 

Peter Hull commented on FOP-3173:
---------------------------------

I wonder if this is a bug actually, because the constructor for URIAction takes 
a URI (in string form) and it has correctly interpreted that as having a scheme 
of 'embedded-file', an ssp of 'filename' and a fragment of '1.txt'.

Your test will pass if you modify it a bit
{code:java}
    @Test
    public void testAddEmbeddedFileDash () throws IFException, 
java.net.URISyntaxException {
        PDFDocumentHandler docHandler = new PDFDocumentHandler(new 
IFContext(ua));
        docHandler.setFontInfo(new FontInfo());
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        docHandler.setResult(new StreamResult(out));
        docHandler.startDocument();
        docHandler.startPage(0, "", "", new Dimension());
        docHandler.handleExtensionObject(new 
PDFEmbeddedFileAttachment("filename#1.txt", "src", "desc"));
        // ** MODIFY next 2 lines 
        URI uri = new URI("embedded-file", "filename#1.txt",null);
        docHandler.getDocumentNavigationHandler().renderLink(new Link(
            new URIAction(uri.toString(), false), new Rectangle()));
        docHandler.endDocument();
    }
{code}
Specifically the URI constructor will escape the hash in the filename (as 
'embedded-file:filename%231.txt')

It might be a good idea to add a constructor to URIAction which takes a URI as 
the first param, to encourage good behaviour.

> cannot include attachment whose name contains hash ('#') in the name
> --------------------------------------------------------------------
>
>                 Key: FOP-3173
>                 URL: https://issues.apache.org/jira/browse/FOP-3173
>             Project: FOP
>          Issue Type: Bug
>          Components: fo/unqualified
>    Affects Versions: 2.9
>            Reporter: BlueMountain
>            Priority: Major
>         Attachments: PDFAttachmentTestCase.java
>
>
> hi,
> we are relying on the fop to generate PDF given data held in database + file 
> storage.
> we need to represent some ( file.name, file.data) as a pdf embedded 
> attachment.
> some users have encountered issue when the file.name value carries hash sign 
> ('#')
> upon generating the pdf, an exception is thrown about missing attachment name.
> I have added a new test to the  PDFAttachmentTestCase class (see attachment) 
> to reproduce the issue.
> The added test that generates the error is:
> @Test
> public void testAddEmbeddedFileDash () throws IFException {
> PDFDocumentHandler docHandler = new PDFDocumentHandler(new IFContext(ua));
> docHandler.setFontInfo(new FontInfo());
> ByteArrayOutputStream out = new ByteArrayOutputStream();
> docHandler.setResult(new StreamResult(out));
> docHandler.startDocument();
> docHandler.startPage(0, "", "", new Dimension());
> docHandler.handleExtensionObject(new 
> PDFEmbeddedFileAttachment("filename#1.txt", "src", "desc"));
> // issue occurs at this line
> *docHandler.getDocumentNavigationHandler().renderLink(new Link(*
>  *new URIAction("embedded-file:filename#1.txt", false), new Rectangle()));*
> docHandler.endDocument();
> }
>  
> running the command: 
> mvn test -pl fop-core -Dtest=PDFAttachmentTestCase
> I get the following output:
> Running org.apache.fop.pdf.PDFAttachmentTestCase
> Tests run: 4, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.15 sec <<< 
> FAILURE! - in org.apache.fop.pdf.PDFAttachmentTestCase
> testAddEmbeddedFileDash(org.apache.fop.pdf.PDFAttachmentTestCase)  Time 
> elapsed: 0.003 sec  <<< ERROR!
> {*}java.lang.IllegalStateException: No embedded file with name filename 
> present{*}.
> at org.apache.fop.pdf.PDFFactory.getActionForEmbeddedFile(PDFFactory.java:728)
> at org.apache.fop.pdf.PDFFactory.getExternalAction(PDFFactory.java:600)
> at 
> org.apache.fop.render.pdf.PDFDocumentNavigationHandler.getAction(PDFDocumentNavigationHandler.java:174)
> at 
> org.apache.fop.render.pdf.PDFDocumentNavigationHandler.renderLink(PDFDocumentNavigationHandler.java:108)
> at 
> org.apache.fop.pdf.PDFAttachmentTestCase.testAddEmbeddedFileDash(PDFAttachmentTestCase.java:119)
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to