[parsing] Make URL parser not eat trailing parentheses
All checks were successful
/ unit-tests (push) Successful in 26s
/ build-and-push (push) Successful in 1m49s

This commit is contained in:
Laura Hausmann 2024-05-07 17:24:27 +02:00
parent b705c95714
commit ef226ee8fe
Signed by: zotan
GPG key ID: D044E84C5BE01605
2 changed files with 24 additions and 17 deletions

View file

@ -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 ->

View file

@ -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<MfmNode> expected =
[
new MfmTextNode("test @test@ test")
];
var res = Mfm.parse(input);
const string input = "test @test@ test";
List<MfmNode> 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<MfmNode> expected =
[
new MfmCodeBlockNode("asd\nsdf", "cs")
];
var res = Mfm.parse(input);
List<MfmNode> 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<MfmNode> 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<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]
public void Benchmark()
{