Merge pull request #876 from Akarinnnnn/fix-872

Fix #872 by reserve null title string.
This commit is contained in:
Alexandre Mutel
2025-06-05 07:57:29 +02:00
committed by GitHub
3 changed files with 8 additions and 8 deletions

View File

@@ -112,26 +112,26 @@ public class TestLinkHelper
}
[Test]
public void TestUrlAndTitleEmpty()
public void TestUrlEmptyAndTitleNull()
{
// 01234
var text = new StringSlice(@"(<>)A");
Assert.True(LinkHelper.TryParseInlineLink(ref text, out string link, out string title, out SourceSpan linkSpan, out SourceSpan titleSpan));
Assert.AreEqual(string.Empty, link);
Assert.AreEqual(string.Empty, title);
Assert.AreEqual(null, title);
Assert.AreEqual(new SourceSpan(1, 2), linkSpan);
Assert.AreEqual(SourceSpan.Empty, titleSpan);
Assert.AreEqual('A', text.CurrentChar);
}
[Test]
public void TestUrlAndTitleEmpty2()
public void TestUrlEmptyAndTitleNull2()
{
// 012345
var text = new StringSlice(@"( <> )A");
Assert.True(LinkHelper.TryParseInlineLink(ref text, out string link, out string title, out SourceSpan linkSpan, out SourceSpan titleSpan));
Assert.AreEqual(string.Empty, link);
Assert.AreEqual(string.Empty, title);
Assert.AreEqual(null, title);
Assert.AreEqual(new SourceSpan(2, 3), linkSpan);
Assert.AreEqual(SourceSpan.Empty, titleSpan);
Assert.AreEqual('A', text.CurrentChar);
@@ -158,7 +158,7 @@ public class TestLinkHelper
var text = new StringSlice(@"()A");
Assert.True(LinkHelper.TryParseInlineLink(ref text, out string link, out string title, out SourceSpan linkSpan, out SourceSpan titleSpan));
Assert.AreEqual(string.Empty, link);
Assert.AreEqual(string.Empty, title);
Assert.AreEqual(null, title);
Assert.AreEqual(SourceSpan.Empty, linkSpan);
Assert.AreEqual(SourceSpan.Empty, titleSpan);
Assert.AreEqual('A', text.CurrentChar);

View File

@@ -411,7 +411,7 @@ public static class LinkHelper
{
// Skip ')'
text.SkipChar();
title ??= string.Empty;
// not to normalize nulls into empty strings, since LinkInline.Title property is nullable.
}
return isValid;
@@ -1565,4 +1565,4 @@ public static class LinkHelper
label = buffer.ToString();
return true;
}
}
}

View File

@@ -260,7 +260,7 @@ public class LinkInlineParser : InlineParser
link = new LinkInline()
{
Url = HtmlHelper.Unescape(url, removeBackSlash: false),
Title = HtmlHelper.Unescape(title, removeBackSlash: false),
Title = title is null ? null : HtmlHelper.Unescape(title, removeBackSlash: false),
IsImage = openParent.IsImage,
LabelSpan = openParent.LabelSpan,
UrlSpan = inlineState.GetSourcePositionFromLocalSpan(linkSpan),