[parsing] Make URL parser not eat trailing parentheses

This commit is contained in:
Laura Hausmann 2024-05-07 17:24:27 +02:00
parent b705c95714
commit ef226ee8fe
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 24 additions and 17 deletions

View file

@ -248,7 +248,7 @@ module private MfmParser =
let urlNodePlain = let urlNodePlain =
lookAhead (skipString "https://" <|> skipString "http://") 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 -> >>= fun uri ->
match Uri.TryCreate(uri, UriKind.Absolute) with match Uri.TryCreate(uri, UriKind.Absolute) with
| true, finalUri -> | true, finalUri ->

View file

@ -82,10 +82,7 @@ public class MfmTests
public void TestInvalidMention() public void TestInvalidMention()
{ {
const string input = "test @test@ test"; const string input = "test @test@ test";
List<MfmNode> expected = List<MfmNode> expected = [new MfmTextNode("test @test@ test")];
[
new MfmTextNode("test @test@ test")
];
var res = Mfm.parse(input); var res = Mfm.parse(input);
AssertionOptions.FormattingOptions.MaxDepth = 100; AssertionOptions.FormattingOptions.MaxDepth = 100;
@ -126,10 +123,7 @@ public class MfmTests
``` ```
"""; """;
List<MfmNode> expected = List<MfmNode> expected = [new MfmCodeBlockNode("asd\nsdf", "cs")];
[
new MfmCodeBlockNode("asd\nsdf", "cs")
];
var res = Mfm.parse(input); var res = Mfm.parse(input);
AssertionOptions.FormattingOptions.MaxDepth = 100; AssertionOptions.FormattingOptions.MaxDepth = 100;
@ -159,6 +153,19 @@ public class MfmTests
MfmSerializer.Serialize(res).Should().BeEquivalentTo(input); MfmSerializer.Serialize(res).Should().BeEquivalentTo(input);
} }
[TestMethod]
public void TestUrl()
{
const string input = "https://example.org/path/Name_(test)_asdf";
//TODO: List<MfmNode> expected = [new MfmUrlNode(input, false),];
List<MfmNode> 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] [TestMethod]
public void Benchmark() public void Benchmark()
{ {