From ce8ed1341c9ea0eb7fb6a1356e46b67af7404e77 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 28 Oct 2016 18:24:22 +0200 Subject: [PATCH] Ignore question and exclamation marks at the end of links, too --- .../java/net/pterodactylus/sone/text/SoneTextParser.java | 2 +- .../net/pterodactylus/sone/text/SoneTextParserTest.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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. -- 2.7.4