diff options
author | Sauli Tähkäpää <sauli@vaadin.com> | 2015-02-03 15:02:45 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-02-13 10:51:12 +0000 |
commit | af6dd56e89db8ea8c88f607c4214abcde50dfc94 (patch) | |
tree | ee6cf0625f444c23e7ab05383b38e4a759803fba /server/tests/src | |
parent | 93ab31a485730394018ac7358f3fb00b258037ad (diff) | |
download | vaadin-framework-af6dd56e89db8ea8c88f607c4214abcde50dfc94.tar.gz vaadin-framework-af6dd56e89db8ea8c88f607c4214abcde50dfc94.zip |
Encode filenames to UTF-8 in Content-Disposition header. (#16556)
Change-Id: Ie2cf41f2176d05105663cdb84934379efa826f03
Diffstat (limited to 'server/tests/src')
-rw-r--r-- | server/tests/src/com/vaadin/server/FileDownloaderTests.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/server/tests/src/com/vaadin/server/FileDownloaderTests.java b/server/tests/src/com/vaadin/server/FileDownloaderTests.java new file mode 100644 index 0000000000..4e9478c570 --- /dev/null +++ b/server/tests/src/com/vaadin/server/FileDownloaderTests.java @@ -0,0 +1,41 @@ +package com.vaadin.server; + +import static org.mockito.Matchers.contains; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URLEncoder; + +import org.junit.Before; +import org.junit.Test; + +public class FileDownloaderTests { + private String filename = "日本語.png"; + private DownloadStream stream; + + @Before + public void setup() { + stream = new DownloadStream(mock(InputStream.class), "", filename); + } + + @Test + public void contentDispositionFilenameIsUtf8Encoded() throws IOException { + VaadinResponse response = mock(VaadinResponse.class); + + stream.writeResponse(mock(VaadinRequest.class), response); + + verify(response).setHeader(eq("Content-Disposition"), + contains("attachment;")); + String encodedFileName = URLEncoder.encode(filename, "utf-8"); + verify(response).setHeader(eq("Content-Disposition"), + contains(String.format("filename=\"%s\";", encodedFileName))); + verify(response) + .setHeader( + eq("Content-Disposition"), + contains(String.format("filename*=utf-8''%s", + encodedFileName))); + } +} |