Skip to content

Commit 9acab0b

Browse files
committed
Not adding colon if the imageOrIcon starts with http
Fixing regression issue due to #4
1 parent 7b3a64b commit 9acab0b

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/main/java/in/ashwanthkumar/slack/webhook/Slack.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import in.ashwanthkumar.slack.webhook.service.SlackService;
44
import in.ashwanthkumar.utils.collections.Lists;
5+
import in.ashwanthkumar.utils.lang.StringUtils;
56

67
import java.io.IOException;
78
import java.net.InetSocketAddress;
@@ -82,7 +83,7 @@ public Slack displayName(String user) {
8283
* @param imageOrIcon Icon Image URL or emoji code from http://www.emoji-cheat-sheet.com/
8384
*/
8485
public Slack icon(String imageOrIcon) {
85-
if (imageOrIcon != null && !imageOrIcon.isEmpty()) {
86+
if (StringUtils.isNotEmpty(imageOrIcon) && !StringUtils.startsWith(imageOrIcon, "http")) {
8687
if (!imageOrIcon.startsWith(":")) {
8788
imageOrIcon = ":" + imageOrIcon;
8889
}

src/test/java/in/ashwanthkumar/slack/webhook/SlackTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,15 @@ public void shouldNotAddColonToIconNameIfAlreadyExists() throws IOException {
6262
assertThat(iconCaptor.getValue(), is(":ghost:"));
6363
}
6464

65+
@Test
66+
public void shouldNotAddColonToIconNameOrImageIfUrl() throws IOException {
67+
Slack slack = new Slack("mockUrl", slackService);
68+
slack.icon("http://github.com/i/am/sorry.png");
69+
ArgumentCaptor<String> iconCaptor = ArgumentCaptor.forClass(String.class);
70+
SlackMessage message = new SlackMessage("hello");
71+
doNothing().when(slackService).push(anyString(), eq(message), anyString(), iconCaptor.capture(), anyString(), anyString());
72+
slack.sendToChannel("test-channel").push(message);
73+
assertThat(iconCaptor.getValue(), is("http://github.com/i/am/sorry.png"));
74+
}
75+
6576
}

0 commit comments

Comments
 (0)