Skip to content

Commit

Permalink
Merge pull request #784 from jgardo/twitter
Browse files Browse the repository at this point in the history
Fix full twitter account url
  • Loading branch information
tdziurko committed Feb 8, 2024
2 parents 461cc1a + 91c8a61 commit 4aeefb8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/main/java/com/jvm_bloggers/core/utils/LinkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ public class LinkUtils {
private static final String TWITTER_HOME_URL = "https://twitter.com/";

public static String getFullTwitterAccountUrl(String twitterHandle) {
return TWITTER_HOME_URL + twitterHandle;
if (twitterHandle == null) {
return TWITTER_HOME_URL;
}
if (twitterHandle.startsWith("@")) {
return TWITTER_HOME_URL + twitterHandle.substring(1);
}
return TWITTER_HOME_URL;
}

}
4 changes: 2 additions & 2 deletions src/test/groovy/com/jvm_bloggers/utils/LinksSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class LinksSpec extends Specification {
LinkUtils.getFullTwitterAccountUrl(twitterHandle) == fullUrl
where:
twitterHandle | fullUrl
"@tnurkiewicz" | "https://twitter.com/@tnurkiewicz"
"@jkubrynski" | "https://twitter.com/@jkubrynski"
"@tnurkiewicz" | "https://twitter.com/tnurkiewicz"
"@jkubrynski" | "https://twitter.com/jkubrynski"
}

}

0 comments on commit 4aeefb8

Please sign in to comment.