diff options
Diffstat (limited to 'src/test/java/com/juick/MessageTest.java')
-rw-r--r-- | src/test/java/com/juick/MessageTest.java | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/test/java/com/juick/MessageTest.java b/src/test/java/com/juick/MessageTest.java index 14d6175a..e750f652 100644 --- a/src/test/java/com/juick/MessageTest.java +++ b/src/test/java/com/juick/MessageTest.java @@ -213,8 +213,8 @@ public class MessageTest { assertThat(MessageUtils.formatMessage(msg), is("<blockquote>quote</blockquote>message")); String brokenComment = "<!-- read next"; assertThat(MessageUtils.formatMessage(brokenComment), is("<!-- read next")); - String url = "[ya](http://ya.ru)"; - assertThat(MessageUtils.formatMessage(url), is("<a href=\"http://ya.ru\" rel=\"nofollow\">ya</a>")); + String url = "test [ya](https://juick.com/a/1)? hh"; + assertThat(MessageUtils.formatMessage(url), is("test <a href=\"https://juick.com/a/1\" rel=\"nofollow\">ya</a>? hh")); String complexMessage = "У футболистов нет мозгов. Что в России, что в Беларуси:\n" + "\n" + ">Отец футболиста Лухвича, объехавшего пробку по тротуару: «Сына задержали, Infiniti арестовали» https://auto.onliner.by/2019/01/23/probka-9\n" + @@ -238,4 +238,16 @@ public class MessageTest { testMessage.setTags(MessageUtils.parseTags("NSFW test")); assertThat(MessageUtils.isSensitive(testMessage), is(true)); } + @Test + public void stripHashesTest() { + var safeMessage = "And that is a [odd](https://juick.com/a/1)? aaapaa"; + var nonsafeMessage = "[Here is my link](https://juick.com?hash=12345)"; + var filteredMessage = "[Here is my link](https://juick.com)"; + var pidginMessage = "I'm very smart to post my login url there<https://juick.com/settings?hash=VTYZkKV8FWkmu6g1>"; + var westernMessage = "«Please, verify your account at https://juick.com/settings?hash=12345»"; + assertThat(MessageUtils.stripNonSafeUrls(safeMessage), is(safeMessage)); + assertThat(MessageUtils.stripNonSafeUrls(nonsafeMessage), is(filteredMessage)); + assertThat(MessageUtils.stripNonSafeUrls(pidginMessage), not(containsString("VTYZkKV8FWkmu6g1"))); + assertThat(MessageUtils.stripNonSafeUrls(westernMessage), containsString("»")); + } } |