diff --git a/pom.xml b/pom.xml index f43ebc2..e358980 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ kemitix-trello - 1.0.2 + 1.0.3 2.18 diff --git a/src/main/java/net/kemitix/trello/TrelloAttachment.java b/src/main/java/net/kemitix/trello/TrelloAttachment.java index d214b77..96dab20 100644 --- a/src/main/java/net/kemitix/trello/TrelloAttachment.java +++ b/src/main/java/net/kemitix/trello/TrelloAttachment.java @@ -8,7 +8,10 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; +import java.net.URLEncoder; import java.nio.channels.Channels; +import java.nio.charset.StandardCharsets; +import java.text.Normalizer; import java.util.Optional; import java.util.logging.Logger; @@ -45,7 +48,12 @@ public class TrelloAttachment implements Attachment { @Override public File getFilename() { return new File(String.format("%4s - %s.%s", - id, card.getName(), extension())); + id, safeCardName(), extension())); + } + + private String safeCardName() { + String normalize = Normalizer.normalize(card.getName(), Normalizer.Form.NFD); + return normalize.replaceAll("[^\\p{ASCII}]", ""); } private String extension() { diff --git a/src/test/java/net/kemitix/trello/TrelloAttachmentTest.java b/src/test/java/net/kemitix/trello/TrelloAttachmentTest.java index 48497db..e9dd55d 100644 --- a/src/test/java/net/kemitix/trello/TrelloAttachmentTest.java +++ b/src/test/java/net/kemitix/trello/TrelloAttachmentTest.java @@ -27,4 +27,23 @@ public class TrelloAttachmentTest //then assertThat(filename.getName()).endsWith(".extension"); } + + @Test + void convertsUnsafeFilename() { + //given + Attachment attachment = new Attachment(); + attachment.setUrl("file.txt"); + Card card = new Card(); + card.setIdShort("123"); + card.setName("Card name Á"); + AttachmentDirectory dir = new AttachmentDirectoryImpl(); + var trelloAttachment = TrelloAttachment.create( + attachment, card, dir + ); + //when + File filename = trelloAttachment.getFilename(); + //then + assertThat(filename.getName()).doesNotContain("Á"); + assertThat(filename.getName()).isEqualTo(" 123 - Card name A.txt"); + } }