diff --git a/src/main/java/in/ashwanthkumar/slack/webhook/Slack.java b/src/main/java/in/ashwanthkumar/slack/webhook/Slack.java index fdd3984..0188b7e 100644 --- a/src/main/java/in/ashwanthkumar/slack/webhook/Slack.java +++ b/src/main/java/in/ashwanthkumar/slack/webhook/Slack.java @@ -2,6 +2,7 @@ import in.ashwanthkumar.slack.webhook.service.SlackService; import in.ashwanthkumar.utils.collections.Lists; +import in.ashwanthkumar.utils.lang.StringUtils; import java.io.IOException; import java.net.InetSocketAddress; @@ -82,7 +83,7 @@ public Slack displayName(String user) { * @param imageOrIcon Icon Image URL or emoji code from http://www.emoji-cheat-sheet.com/ */ public Slack icon(String imageOrIcon) { - if (imageOrIcon != null && !imageOrIcon.isEmpty()) { + if (StringUtils.isNotEmpty(imageOrIcon) && !StringUtils.startsWith(imageOrIcon, "http")) { if (!imageOrIcon.startsWith(":")) { imageOrIcon = ":" + imageOrIcon; } diff --git a/src/test/java/in/ashwanthkumar/slack/webhook/SlackTest.java b/src/test/java/in/ashwanthkumar/slack/webhook/SlackTest.java index 704571c..19ab9ec 100644 --- a/src/test/java/in/ashwanthkumar/slack/webhook/SlackTest.java +++ b/src/test/java/in/ashwanthkumar/slack/webhook/SlackTest.java @@ -62,4 +62,15 @@ public void shouldNotAddColonToIconNameIfAlreadyExists() throws IOException { assertThat(iconCaptor.getValue(), is(":ghost:")); } + @Test + public void shouldNotAddColonToIconNameOrImageIfUrl() throws IOException { + Slack slack = new Slack("mockUrl", slackService); + slack.icon("http://github.com/i/am/sorry.png"); + ArgumentCaptor iconCaptor = ArgumentCaptor.forClass(String.class); + SlackMessage message = new SlackMessage("hello"); + doNothing().when(slackService).push(anyString(), eq(message), anyString(), iconCaptor.capture(), anyString(), anyString()); + slack.sendToChannel("test-channel").push(message); + assertThat(iconCaptor.getValue(), is("http://github.com/i/am/sorry.png")); + } + } \ No newline at end of file