Skip to content

Commit

Permalink
Merge pull request #357 from MihaZupan/master
Browse files Browse the repository at this point in the history
Ignore backticks in GFM AutoLinks
  • Loading branch information
xoofx authored Jul 17, 2019
2 parents f3f7584 + 033ddaf commit 2595917
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
10 changes: 10 additions & 0 deletions src/Markdig.Tests/MiscTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ namespace Markdig.Tests
{
public class MiscTests
{
[Test]
public void IsIssue356Corrected()
{
string input = @"https://foo.bar/path/\#m4mv5W0GYKZpGvfA.97";
string expected = @"<p><a href=""https://foo.bar/path/%5C#m4mv5W0GYKZpGvfA.97"">https://foo.bar/path/\#m4mv5W0GYKZpGvfA.97</a></p>";

TestParser.TestSpec($"<{input}>", expected);
TestParser.TestSpec(input, expected, "autolinks|advanced");
}

[Test]
public void TestAltTextIsCorrectlyEscaped()
{
Expand Down
30 changes: 15 additions & 15 deletions src/Markdig/Helpers/LinkHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -597,20 +597,23 @@ public static bool TryParseUrl<T>(ref T text, out string link, bool isAutoLink =
}
}

if (hasEscape && !c.IsAsciiPunctuation())
if (!isAutoLink)
{
buffer.Append('\\');
}
if (hasEscape && !c.IsAsciiPunctuation())
{
buffer.Append('\\');
}

// If we have an escape
if (c == '\\')
{
hasEscape = true;
c = text.NextChar();
continue;
}
// If we have an escape
if (c == '\\')
{
hasEscape = true;
c = text.NextChar();
continue;
}

hasEscape = false;
hasEscape = false;
}

if (IsEndOfUri(c, isAutoLink))
{
Expand All @@ -622,10 +625,7 @@ public static bool TryParseUrl<T>(ref T text, out string link, bool isAutoLink =
{
if (c == '&')
{
int entityNameStart;
int entityNameLength;
int entityValue;
if (HtmlHelper.ScanEntity(text, out entityValue, out entityNameStart, out entityNameLength) > 0)
if (HtmlHelper.ScanEntity(text, out _, out _, out _) > 0)
{
isValid = true;
break;
Expand Down

0 comments on commit 2595917

Please sign in to comment.