diff --git a/src/Markdig.Tests/TestLinkHelper.cs b/src/Markdig.Tests/TestLinkHelper.cs index d46c50ab..b9a15292 100644 --- a/src/Markdig.Tests/TestLinkHelper.cs +++ b/src/Markdig.Tests/TestLinkHelper.cs @@ -112,26 +112,26 @@ public void TestUrlAndTitle() } [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 void TestUrlEmpty() 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); diff --git a/src/Markdig/Helpers/LinkHelper.cs b/src/Markdig/Helpers/LinkHelper.cs index b76cddca..c5004594 100644 --- a/src/Markdig/Helpers/LinkHelper.cs +++ b/src/Markdig/Helpers/LinkHelper.cs @@ -411,7 +411,7 @@ public static bool TryParseInlineLink(ref StringSlice text, out string? link, ou { // 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 bool TryParseLabelTrivia(ref T lines, bool allowEmpty, out stri label = buffer.ToString(); return true; } -} \ No newline at end of file +} diff --git a/src/Markdig/Parsers/Inlines/LinkInlineParser.cs b/src/Markdig/Parsers/Inlines/LinkInlineParser.cs index eee94ec7..a9687a31 100644 --- a/src/Markdig/Parsers/Inlines/LinkInlineParser.cs +++ b/src/Markdig/Parsers/Inlines/LinkInlineParser.cs @@ -260,7 +260,7 @@ private bool TryProcessLinkOrImage(InlineProcessor inlineState, ref StringSlice 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),