From: David ‘Bombe’ Roden Date: Fri, 28 Oct 2016 16:24:22 +0000 (+0200) Subject: Ignore question and exclamation marks at the end of links, too X-Git-Tag: 0.9.7^2~472 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=ce8ed1341c9ea0eb7fb6a1356e46b67af7404e77;p=Sone.git Ignore question and exclamation marks at the end of links, too --- diff --git a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java index 81ac751..bd389e1 100644 --- a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java +++ b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java @@ -322,7 +322,7 @@ public class SoneTextParser implements Parser { } private static boolean isPunctuation(char character) { - return (character == '.') || (character == ','); + return (character == '.') || (character == ',') || (character == '!') || (character == '?'); } private static class NextLink { diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java index 6483171..bb8c711 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -317,6 +317,22 @@ public class SoneTextParserTest { assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc], nice!")); } + @Test + public void exclamationMarksAreIgnoredAtEndOfLinkBeforeWhitespace() { + SoneTextParser soneTextParser = new SoneTextParser(null, null); + Iterable parts = soneTextParser.parse("A link: http://example.sone/abc!", null); + assertThat("Parts", parts, notNullValue()); + assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("A link: [http://example.sone/abc|example.sone/abc|example.sone/abc]!")); + } + + @Test + public void questionMarksAreIgnoredAtEndOfLinkBeforeWhitespace() { + SoneTextParser soneTextParser = new SoneTextParser(null, null); + Iterable parts = soneTextParser.parse("A link: http://example.sone/abc?", null); + assertThat("Parts", parts, notNullValue()); + assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("A link: [http://example.sone/abc|example.sone/abc|example.sone/abc]?")); + } + /** * Converts all given {@link Part}s into a string, validating that the * part’s classes match only the expected classes.