From: David ‘Bombe’ Roden Date: Sat, 20 May 2017 10:40:09 +0000 (+0200) Subject: Fix text parser only parsing the last element in a line X-Git-Tag: 0.9.7^2~216 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=7d52ecea5a10feaae9fcd86415a3c6f41edc72fa;p=Sone.git Fix text parser only parsing the last element in a line --- diff --git a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java index c3c4068..39d26db 100644 --- a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java +++ b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java @@ -334,6 +334,7 @@ public class SoneTextParser implements Parser { if (nextLink.isPresent()) { if (nextLink.get().getPosition() < earliestLinkPosition) { earliestNextLink = nextLink.get(); + earliestLinkPosition = earliestNextLink.getPosition(); } } } diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java index e640c7d..0daf944 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -93,6 +93,13 @@ public class SoneTextParserTest { } @Test + public void soneAndPostCanBeParsedFromTheSameText() { + SoneTextParser parser = new SoneTextParser(new TestSoneProvider(), new TestPostProvider()); + Iterable parts = parser.parse("Text sone://DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU more text post://f3757817-b45a-497a-803f-9c5aafc10dc6 even more text", null); + assertThat("Part Text", convertText(parts), is("Text [Sone|DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU] more text [Post|f3757817-b45a-497a-803f-9c5aafc10dc6|text] even more text")); + } + + @Test public void postLinkIsRenderedAsPlainTextIfPostIdIsTooShort() { Iterable parts = soneTextParser.parse("post://too-short", null); assertThat("Part Text", convertText(parts), is("post://too-short"));