From ef226ee8fed33c810d394882ab658da3b220812f Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Tue, 7 May 2024 17:24:27 +0200 Subject: [PATCH] [parsing] Make URL parser not eat trailing parentheses --- Iceshrimp.Parsing/Mfm.fs | 2 +- Iceshrimp.Tests/Parsing/MfmTests.cs | 39 +++++++++++++++++------------ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/Iceshrimp.Parsing/Mfm.fs b/Iceshrimp.Parsing/Mfm.fs index 0f8413ed..6983a4c1 100644 --- a/Iceshrimp.Parsing/Mfm.fs +++ b/Iceshrimp.Parsing/Mfm.fs @@ -248,7 +248,7 @@ module private MfmParser = let urlNodePlain = lookAhead (skipString "https://" <|> skipString "http://") - >>. manyCharsTill anyChar (nextCharSatisfies isWhitespace <|> skipAnyOf "()" <|> eof) //FIXME: this needs significant improvements + >>. manyCharsTill anyChar (nextCharSatisfies isWhitespace <|> nextCharSatisfies (isAnyOf "()") <|> eof) //FIXME: this needs significant improvements >>= fun uri -> match Uri.TryCreate(uri, UriKind.Absolute) with | true, finalUri -> diff --git a/Iceshrimp.Tests/Parsing/MfmTests.cs b/Iceshrimp.Tests/Parsing/MfmTests.cs index 250929f2..2ce55e88 100644 --- a/Iceshrimp.Tests/Parsing/MfmTests.cs +++ b/Iceshrimp.Tests/Parsing/MfmTests.cs @@ -77,16 +77,13 @@ public class MfmTests res.ToList().Should().Equal(expected, MfmNodeEqual); MfmSerializer.Serialize(res).Should().BeEquivalentTo(input); } - + [TestMethod] public void TestInvalidMention() { - const string input = "test @test@ test"; - List expected = - [ - new MfmTextNode("test @test@ test") - ]; - var res = Mfm.parse(input); + const string input = "test @test@ test"; + List expected = [new MfmTextNode("test @test@ test")]; + var res = Mfm.parse(input); AssertionOptions.FormattingOptions.MaxDepth = 100; res.ToList().Should().Equal(expected, MfmNodeEqual); @@ -115,7 +112,7 @@ public class MfmTests res.ToList().Should().Equal(expected, MfmNodeEqual); MfmSerializer.Serialize(res).Should().BeEquivalentTo(input); } - + [TestMethod] public void TestCodeBlockMultiLine() { @@ -125,23 +122,20 @@ public class MfmTests sdf ``` """; - - List expected = - [ - new MfmCodeBlockNode("asd\nsdf", "cs") - ]; - var res = Mfm.parse(input); + + List expected = [new MfmCodeBlockNode("asd\nsdf", "cs")]; + var res = Mfm.parse(input); AssertionOptions.FormattingOptions.MaxDepth = 100; 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 "), @@ -159,6 +153,19 @@ public class MfmTests MfmSerializer.Serialize(res).Should().BeEquivalentTo(input); } + [TestMethod] + public void TestUrl() + { + const string input = "https://example.org/path/Name_(test)_asdf"; + //TODO: List expected = [new MfmUrlNode(input, false),]; + List expected = [new MfmUrlNode(input[..30], false), new MfmTextNode(input[30..])]; + 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() {