From 44162f71e128ec940d1c8ce79103fa8b8a6f53c6 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 29 Aug 2014 12:18:19 -0700 Subject: 442726: Attachments with unicode characters in file names get submitted wrongly Change-Id: Ib46683040f56fb0d524108ada844ef0d76a06907 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=442726 Signed-off-by: David King --- .../tests/BugzillaAttachmentHandlerTest.java | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'org.eclipse.mylyn.bugzilla.tests') diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java index 3f278c6da..4db4e8fbf 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java @@ -19,6 +19,7 @@ import java.io.FileOutputStream; import java.io.FileWriter; import java.io.OutputStream; import java.util.Date; +import java.util.List; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; @@ -311,6 +312,58 @@ public class BugzillaAttachmentHandlerTest extends AbstractBugzillaTest { assertTrue(attachFile.delete()); } + public void testAttachmentWithUnicode() throws Exception { + testAttachmentWithSpecialCharacters("\u00E7\u00F1\u00A5\u20AC\u00A3\u00BD\u00BC\u03B2\u03B8\u53F0\u5317\u3096\u3097\uFF73"); + } + + public void testAttachmentWithSpecialCharacters() throws Exception { + testAttachmentWithSpecialCharacters("~`!@#$%^&()_-+={[}];',"); + } + + private void testAttachmentWithSpecialCharacters(String specialCharacters) throws Exception { + TaskData taskData = BugzillaFixture.current().createTask(PrivilegeLevel.USER, null, null); + assertNotNull(taskData); + + TaskAttribute attachmentAttr = taskData.getAttributeMapper().createTaskAttachment(taskData); + TaskAttachmentMapper attachmentMapper = TaskAttachmentMapper.createFrom(attachmentAttr); + + String description = "Test attachment " + specialCharacters + System.currentTimeMillis(); + attachmentMapper.setDescription(description); + attachmentMapper.setContentType("text/plain"); + attachmentMapper.setPatch(false); + attachmentMapper.applyTo(attachmentAttr); + + String filename = "test" + specialCharacters + System.currentTimeMillis() + ".txt"; + File attachFile = new File(filename); + attachFile.createNewFile(); + attachFile.deleteOnExit(); + BufferedWriter write = new BufferedWriter(new FileWriter(attachFile)); + write.write("test file content"); + write.close(); + + FileTaskAttachmentSource attachment = new FileTaskAttachmentSource(attachFile); + attachment.setContentType("text/plain"); + attachment.setDescription(description); + attachment.setName(filename); + + client.postAttachment(taskData.getTaskId(), attachmentMapper.getComment(), attachment, attachmentAttr, + new NullProgressMonitor()); + + taskData = BugzillaFixture.current().getTask(taskData.getTaskId(), client); + assertNotNull(taskData); + List attachmentAttrs = taskData.getAttributeMapper().getAttributesByType(taskData, + TaskAttribute.TYPE_ATTACHMENT); + assertEquals(1, attachmentAttrs.size()); + + attachmentMapper = TaskAttachmentMapper.createFrom(attachmentAttrs.get(0)); + assertEquals(description, attachmentMapper.getDescription()); + assertEquals(filename, attachmentMapper.getFileName()); + assertEquals("text/plain", attachmentMapper.getContentType()); + assertEquals(Boolean.FALSE, attachmentMapper.isPatch()); + + assertTrue(attachFile.delete()); + } + private void assertFileEmptyError(Exception e) { if (BugzillaFixture.current().getBugzillaVersion().compareTo(BugzillaVersion.BUGZILLA_4_5_2) >= 0) { assertEquals("An unknown repository error has occurred: file is empty", e.getMessage()); -- cgit v1.2.3