diff --git a/pom.xml b/pom.xml
index 74c1eeb..f43ebc2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,7 +12,7 @@
kemitix-trello
- 1.0.1
+ 1.0.2
2.18
diff --git a/src/main/java/net/kemitix/trello/TrelloAttachment.java b/src/main/java/net/kemitix/trello/TrelloAttachment.java
index 1a2bfcd..d214b77 100644
--- a/src/main/java/net/kemitix/trello/TrelloAttachment.java
+++ b/src/main/java/net/kemitix/trello/TrelloAttachment.java
@@ -9,6 +9,7 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.channels.Channels;
+import java.util.Optional;
import java.util.logging.Logger;
public class TrelloAttachment implements Attachment {
@@ -17,7 +18,6 @@ public class TrelloAttachment implements Attachment {
Logger.getLogger(
TrelloAttachment.class.getName());
- private static final String[] EXTENSIONS = new String[]{"doc", "docx", "odt"};
private final com.julienvey.trello.domain.Attachment attachment;
private final Card card;
private final AttachmentDirectory attachmentDirectory;
@@ -51,12 +51,10 @@ public class TrelloAttachment implements Attachment {
private String extension() {
URI uri = URI.create(attachment.getUrl());
String path = uri.getPath();
- for (String ex : EXTENSIONS) {
- if (path.endsWith("." + ex)) {
- return ex;
- }
- }
- return "";
+ return Optional.ofNullable(path)
+ .filter(f -> f.contains("."))
+ .map(f -> f.substring(path.lastIndexOf(".") + 1))
+ .orElse("");
}
@Override
diff --git a/src/test/java/net/kemitix/trello/TrelloAttachmentTest.java b/src/test/java/net/kemitix/trello/TrelloAttachmentTest.java
new file mode 100644
index 0000000..48497db
--- /dev/null
+++ b/src/test/java/net/kemitix/trello/TrelloAttachmentTest.java
@@ -0,0 +1,30 @@
+package net.kemitix.trello;
+
+import com.julienvey.trello.domain.Attachment;
+import com.julienvey.trello.domain.Card;
+import org.assertj.core.api.WithAssertions;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+
+public class TrelloAttachmentTest
+ implements WithAssertions {
+
+ @Test
+ void regressionExtensionTruncated() {
+ //given
+ Attachment attachment = new Attachment();
+ attachment.setUrl("card-url.extension");
+ 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()).endsWith(".extension");
+ }
+}