[
https://issues.apache.org/jira/browse/WW-5867?focusedWorklogId=1056566&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1056566
]
ASF GitHub Bot logged work on WW-5867:
--------------------------------------
Author: ASF GitHub Bot
Created on: 23/Nov/26 05:35
Start Date: 23/Nov/26 05:35
Worklog Time Spent: 10m
Work Description: rootvector2 commented on code in PR #2150:
URL: https://github.com/apache/struts/pull/2150#discussion_r4662151401
##########
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:
Done, collapsed to the one-liner citing RFC 9110 §5.6.4 in both
`quoteFileName` helpers.
##########
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:
Switched both tests to `"sales \"Q1\"; 2026\tdraft"`, expecting
`filename="sales \"Q1\"; 2026draft.xml"`. Still covers space, `;`, `"` and a
dropped control character.
##########
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:
Fixed.
Issue Time Tracking
-------------------
Worklog Id: (was: 1056566)
Time Spent: 0.5h (was: 20m)
> 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: 0.5h
> 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)