[ 
https://issues.apache.org/jira/browse/WW-5867?focusedWorklogId=1056379&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1056379
 ]

ASF GitHub Bot logged work on WW-5867:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 21/Nov/26 10:42
            Start Date: 21/Nov/26 10:42
    Worklog Time Spent: 10m 
      Work Description: lukaszlenart commented on code in PR #2150:
URL: https://github.com/apache/struts/pull/2150#discussion_r4652071166


##########
plugins/jasperreports/src/main/java/org/apache/struts2/views/jasperreports/JasperReportsResult.java:
##########
@@ -488,6 +486,28 @@ private void initializeProperties(ActionInvocation 
invocation) {
         parsedExportParameters = conditionalParse(exportParameters, 
invocation);
     }
 
+    /**
+     * Formats a file name as an RFC 6266 quoted-string, so spaces, semicolons 
and quotes in the

Review Comment:
   Nit: a one-line comment is enough for a private helper, and quoted-string is 
defined in RFC 9110 §5.6.4 (RFC 6266 refers to it), e.g. `/** Formats the file 
name as an RFC 9110 quoted-string. */`. Same in `JasperReport7Result`.



##########
plugins/jasperreports/src/test/java/org/apache/struts2/views/jasperreports/JasperReportsResultTest.java:
##########
@@ -268,6 +268,21 @@ public Map<Object, Object> getExportParameters() {
         assertTrue(sb.toString().contains("Hello Qux Quux!"));
     }
 
+    public void testDocumentNameIsQuotedInContentDisposition() throws 
Exception {
+        result.setDataSource("{#{'firstName':'ignore', 'lastName':'ignore'}}");
+        stack.push(new Object() {
+            public String getReportName() {
+                return "sales \"Q1\"; 2026\r\nX-Injected: 1";

Review Comment:
   Could the test data be a plain document name with a control character, e.g. 
`"sales \"Q1\"; 2026\tdraft"`? It covers the same cases (space, `;`, `"`, a 
dropped control character) and reads as an ordinary file name. Same in 
`JasperReport7ResultTest`.



##########
plugins/jasperreports7/src/test/java/org/apache/struts2/views/jasperreports7/JasperReport7ResultTest.java:
##########
@@ -383,6 +383,23 @@ public void testExportToXlsx() throws Exception {
         
assertThat(response.getContentType()).isEqualTo("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
         assertThat(response.getContentAsByteArray()).hasSizeGreaterThan(0);
     }
+    public void testDocumentNameIsQuotedInContentDisposition() throws 
Exception {

Review Comment:
   Nit: missing blank line between `testExportToXlsx()` and this method.





Issue Time Tracking
-------------------

            Worklog Id:     (was: 1056379)
    Remaining Estimate: 0h
            Time Spent: 10m

> JasperReports results write the Content-Disposition filename unquoted
> ---------------------------------------------------------------------
>
>                 Key: WW-5867
>                 URL: https://issues.apache.org/jira/browse/WW-5867
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - JasperReports
>            Reporter: Lukasz Lenart
>            Priority: Major
>             Fix For: 7.6.0
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> {{JasperReportsResult}} (plugin {{struts2-jasperreports-plugin}}) and 
> {{JasperReport7Result}} (plugin {{struts2-jasperreports7-plugin}}) build the 
> {{Content-disposition}} header by appending {{documentName}} + {{.}} + format 
> as a bare token:
> {code}
> inline; filename=sales report.pdf
> {code}
> When the document name contains a space, {{;}}, {{"}} or a control character 
> — common once {{documentName}} is an expression such as {{${title}}} 
> evaluated against the value stack — the {{filename}} parameter is cut short 
> or split, and browsers save the file under a truncated or wrong name.
> h2. Proposed change
> Write the file name as a quoted-string (RFC 6266 / RFC 9110): wrap it in 
> double quotes, escape {{"}} and {{\}}, drop control characters.
> {code}
> inline; filename="sales report.pdf"
> {code}
> Applies to both plugins. Update the {{documentName}} Javadoc to show the 
> quoted form.
> h2. Tests
> A test in each plugin asserting the header value for a document name 
> containing a space, {{;}}, {{"}} and a control character.
> Contributed by Naveed Khan (rootvector2) in 
> https://github.com/apache/struts/pull/2150.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to