From 69065ef1d71804ea06e830881a9e1504dd73548d Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Thu, 2 May 2024 22:18:04 +0200 Subject: [PATCH] [parsing] Fix hashtag detection (ISH-302) --- Iceshrimp.Parsing/Mfm.fs | 2 +- Iceshrimp.Tests/Parsing/MfmTests.cs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Iceshrimp.Parsing/Mfm.fs b/Iceshrimp.Parsing/Mfm.fs index ec152461..c181a0f5 100644 --- a/Iceshrimp.Parsing/Mfm.fs +++ b/Iceshrimp.Parsing/Mfm.fs @@ -243,7 +243,7 @@ module private MfmParser = let hashtagNode = previousCharSatisfiesNot isNotWhitespace >>. skipChar '#' - >>. many1CharsTill letter (nextCharSatisfies isWhitespace <|> eof) + >>. many1CharsTill letter (nextCharSatisfiesNot isLetter) |>> fun h -> MfmHashtagNode(h) :> MfmNode let urlNodePlain = diff --git a/Iceshrimp.Tests/Parsing/MfmTests.cs b/Iceshrimp.Tests/Parsing/MfmTests.cs index 9e558607..250929f2 100644 --- a/Iceshrimp.Tests/Parsing/MfmTests.cs +++ b/Iceshrimp.Tests/Parsing/MfmTests.cs @@ -136,6 +136,28 @@ public class MfmTests res.ToList().Should().Equal(expected, MfmNodeEqual); MfmSerializer.Serialize(res).Should().BeEquivalentTo(input); } + + [TestMethod] + public void TestHashtag() + { + const string input = "test #test #test's #test. test"; + + List expected = + [ + new MfmTextNode("test "), + new MfmHashtagNode("test"), + new MfmTextNode(" "), + new MfmHashtagNode("test"), + new MfmTextNode("'s "), + new MfmHashtagNode("test"), + new MfmTextNode(". test"), + ]; + var res = Mfm.parse(input); + + AssertionOptions.FormattingOptions.MaxDepth = 100; + res.ToList().Should().Equal(expected, MfmNodeEqual); + MfmSerializer.Serialize(res).Should().BeEquivalentTo(input); + } [TestMethod] public void Benchmark()