Ignore question and exclamation marks at the end of links, too
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Oct 2016 16:24:22 +0000 (18:24 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Oct 2016 16:24:22 +0000 (18:24 +0200)
src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java

index 81ac751..bd389e1 100644 (file)
@@ -322,7 +322,7 @@ public class SoneTextParser implements Parser<SoneTextParserContext> {
        }
 
        private static boolean isPunctuation(char character) {
-               return (character == '.') || (character == ',');
+               return (character == '.') || (character == ',') || (character == '!') || (character == '?');
        }
 
        private static class NextLink {
index 6483171..bb8c711 100644 (file)
@@ -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<Part> 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<Part> 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.