You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by ss...@apache.org on 2026/10/22 10:00:47 UTC

(xmlgraphics-fop) branch main updated: FOP-3362: Add encryption to PDFGoToRemote

This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/xmlgraphics-fop.git


The following commit(s) were added to refs/heads/main by this push:
     new 0d351048f FOP-3362: Add encryption to PDFGoToRemote
0d351048f is described below

commit 0d351048f2e80ecdea68a05c3ce3d61fefd223cf
Author: Simon Steiner <ss...@apache.org>
AuthorDate: Thu Oct 22 11:00:29 2026 +0100

    FOP-3362: Add encryption to PDFGoToRemote
---
 .../java/org/apache/fop/pdf/PDFGoToRemote.java     |  2 +-
 .../org/apache/fop/pdf/PDFGoToRemoteTestCase.java  | 62 ++++++++++++++++++++++
 2 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/fop-core/src/main/java/org/apache/fop/pdf/PDFGoToRemote.java b/fop-core/src/main/java/org/apache/fop/pdf/PDFGoToRemote.java
index ef283e6ad..d0c497af8 100644
--- a/fop-core/src/main/java/org/apache/fop/pdf/PDFGoToRemote.java
+++ b/fop-core/src/main/java/org/apache/fop/pdf/PDFGoToRemote.java
@@ -111,7 +111,7 @@ public class PDFGoToRemote extends PDFAction {
         sb.append("\n");
 
         if (destination != null) {
-            sb.append("/D (").append(this.destination).append(")");
+            sb.append("/D ").append(encodeScript(this.destination));
         } else {
             sb.append("/D [ ").append(this.pageReference).append(" /XYZ null null null ]");
         }
diff --git a/fop-core/src/test/java/org/apache/fop/pdf/PDFGoToRemoteTestCase.java b/fop-core/src/test/java/org/apache/fop/pdf/PDFGoToRemoteTestCase.java
new file mode 100644
index 000000000..300b276b4
--- /dev/null
+++ b/fop-core/src/test/java/org/apache/fop/pdf/PDFGoToRemoteTestCase.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.fop.pdf;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class PDFGoToRemoteTestCase {
+
+    private static final String DEST = "secretDestination";
+
+    private PDFGoToRemote createAction(PDFDocument document) {
+        PDFFileSpec fileSpec = new PDFFileSpec("other.pdf");
+        fileSpec.setObjectNumber(2);
+        PDFGoToRemote action = new PDFGoToRemote(fileSpec, DEST, false);
+        action.setDocument(document);
+        action.setObjectNumber(1);
+        return action;
+    }
+
+    @Test
+    public void testToPDFStringShouldEncryptDestination() {
+        PDFDocument document = new PDFDocument("<test />");
+        document.setEncryption(new PDFEncryptionParams("user", null, false,
+                true, false, true, true));
+        String pdfString = createAction(document).toPDFString();
+        assertFalse(pdfString.contains(DEST));
+        assertTrue(pdfString.contains("/D <"));
+    }
+
+    @Test
+    public void testToPDFStringUnencrypted() {
+        String pdfString = createAction(new PDFDocument("<test />")).toPDFString();
+        assertEquals("<<\n/S /GoToR\n/F 2 0 R\n/D (" + DEST + ")\n>>", pdfString);
+    }
+
+    @Test
+    public void testToPDFStringEscapesDestination() {
+        PDFFileSpec fileSpec = new PDFFileSpec("other.pdf");
+        fileSpec.setObjectNumber(2);
+        PDFGoToRemote action = new PDFGoToRemote(fileSpec, "a)b", false);
+        action.setDocument(new PDFDocument("<test />"));
+        assertTrue(action.toPDFString().contains("/D (a\\)b)"));
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org