Add a test case to demonstate an issue with FPDFAction_GetURIPath().

The FPDFAction_GetFilePath() documentation claims the return value is
7-bit ASCII, but this test case shows that is not always true.

Bug: chromium:1323491
Change-Id: I934618bd111b9ccb566ac1e395175548211670a0
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/94531
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/fpdf_doc_embeddertest.cpp b/fpdfsdk/fpdf_doc_embeddertest.cpp
index a8d8f71..d934684 100644
--- a/fpdfsdk/fpdf_doc_embeddertest.cpp
+++ b/fpdfsdk/fpdf_doc_embeddertest.cpp
@@ -309,7 +309,7 @@
   UnloadPage(page);
 }
 
-TEST_F(FPDFDocEmbedderTest, ActionURI) {
+TEST_F(FPDFDocEmbedderTest, ActionUri) {
   ASSERT_TRUE(OpenDocument("uri_action.pdf"));
 
   FPDF_PAGE page = LoadPage(0);
@@ -340,6 +340,37 @@
   UnloadPage(page);
 }
 
+TEST_F(FPDFDocEmbedderTest, ActionUriNonAscii) {
+  ASSERT_TRUE(OpenDocument("uri_action_nonascii.pdf"));
+
+  FPDF_PAGE page = LoadPage(0);
+  ASSERT_TRUE(page);
+
+  // The target action is nearly the size of the whole page.
+  FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100);
+  ASSERT_TRUE(link);
+
+  FPDF_ACTION action = FPDFLink_GetAction(link);
+  ASSERT_TRUE(action);
+  EXPECT_EQ(static_cast<unsigned long>(PDFACTION_URI),
+            FPDFAction_GetType(action));
+
+  // TODO(crbug.com/1323491): FPDFAction_GetURIPath() claims it only returns
+  // 7-bit ASCII values.
+  const char kExpectedResult[] =
+      "https://example.com/\xA5octal\xC7"
+      "chars";
+  const unsigned long kExpectedLength = sizeof(kExpectedResult);
+  unsigned long bufsize = FPDFAction_GetURIPath(document(), action, nullptr, 0);
+  ASSERT_EQ(kExpectedLength, bufsize);
+
+  char buf[1024];
+  EXPECT_EQ(bufsize, FPDFAction_GetURIPath(document(), action, buf, bufsize));
+  EXPECT_STREQ(kExpectedResult, buf);
+
+  UnloadPage(page);
+}
+
 TEST_F(FPDFDocEmbedderTest, LinkToAnnotConversion) {
   ASSERT_TRUE(OpenDocument("annots.pdf"));
   FPDF_PAGE page = LoadPage(0);
diff --git a/testing/resources/uri_action_nonascii.in b/testing/resources/uri_action_nonascii.in
new file mode 100644
index 0000000..d2ec540
--- /dev/null
+++ b/testing/resources/uri_action_nonascii.in
@@ -0,0 +1,44 @@
+{{header}}
+{{object 1 0}} <<
+  /Type /Catalog
+  /Pages 2 0 R
+>>
+endobj
+{{object 2 0}} <<
+  /Type /Pages
+  /MediaBox [0 0 200 200]
+  /Count 1
+  /Kids [3 0 R]
+>>
+endobj
+{{object 3 0}} <<
+  /Type /Page
+  /Parent 2 0 R
+  /Annots [4 0 R]
+>>
+endobj
+{{object 4 0}} <<
+  /A 5 0 R
+  /FT /Tx
+  /Ff 29360128
+  /Type /Annot
+  /Subtype /Link
+  /F 4
+  /Rect [1 1 199 199]
+  /BS  <<
+    /W 1
+    /S /S
+  >>
+  /DA (/Helv 0 Tf 0 0 0 rg)
+  /V ()
+>>
+endobj
+{{object 5 0}} <<
+  /S /URI
+  /URI (https://example.com/\245octal\307chars)
+>>
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/uri_action_nonascii.pdf b/testing/resources/uri_action_nonascii.pdf
new file mode 100644
index 0000000..ffc084a
--- /dev/null
+++ b/testing/resources/uri_action_nonascii.pdf
@@ -0,0 +1,56 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+  /Type /Catalog
+  /Pages 2 0 R
+>>
+endobj
+2 0 obj <<
+  /Type /Pages
+  /MediaBox [0 0 200 200]
+  /Count 1
+  /Kids [3 0 R]
+>>
+endobj
+3 0 obj <<
+  /Type /Page
+  /Parent 2 0 R
+  /Annots [4 0 R]
+>>
+endobj
+4 0 obj <<
+  /A 5 0 R
+  /FT /Tx
+  /Ff 29360128
+  /Type /Annot
+  /Subtype /Link
+  /F 4
+  /Rect [1 1 199 199]
+  /BS  <<
+    /W 1
+    /S /S
+  >>
+  /DA (/Helv 0 Tf 0 0 0 rg)
+  /V ()
+>>
+endobj
+5 0 obj <<
+  /S /URI
+  /URI (https://example.com/\245octal\307chars)
+>>
+endobj
+xref
+0 6
+0000000000 65535 f 
+0000000015 00000 n 
+0000000068 00000 n 
+0000000157 00000 n 
+0000000226 00000 n 
+0000000414 00000 n 
+trailer <<
+  /Root 1 0 R
+  /Size 6
+>>
+startxref
+493
+%%EOF