mirror of
https://github.com/xoofx/markdig.git
synced 2026-11-16 09:20:40 +00:00
Merge pull request #449 from MihaZupan/invalid-idn-fallback
Fallback to non-punycode encoding for invalid IDN urls
This commit is contained in:
@@ -9,6 +9,20 @@ namespace Markdig.Tests
|
||||
{
|
||||
public class MiscTests
|
||||
{
|
||||
[Test]
|
||||
public void LinkWithInvalidNonAsciiDomainNameIsIgnored()
|
||||
{
|
||||
// Url from https://github.com/lunet-io/markdig/issues/438
|
||||
_ = Markdown.ToHtml("[minulém díle](http://V%20minulém%20díle%20jsme%20nainstalovali%20SQL%20Server,%20který%20je%20nutný%20pro%20běh%20Configuration%20Manageru.%20Dnes%20nás%20čeká%20instalace%20WSUS,%20což%20je%20produkt,%20jež%20je%20možné%20používat%20i%20jako%20samostatnou%20funkci%20ve%20Windows%20Serveru,%20který%20se%20stará%20o%20stažení%20a%20instalaci%20aktualizací%20z%20Microsoft%20Update%20na%20klientské%20počítače.%20Stejně%20jako%20v%20předchozích%20dílech,%20tak%20i%20v%20tomto%20si%20ukážeme%20obě%20varianty%20instalace%20–%20a%20to%20jak%20instalaci%20z%20PowerShellu,%20tak%20instalaci%20pomocí%20GUI.) ");
|
||||
|
||||
// Valid IDN
|
||||
TestParser.TestSpec("[foo](http://ünicode.com)", "<p><a href=\"http://xn--nicode-2ya.com\">foo</a></p>");
|
||||
TestParser.TestSpec("[foo](http://ünicode.ünicode.com)", "<p><a href=\"http://xn--nicode-2ya.xn--nicode-2ya.com\">foo</a></p>");
|
||||
|
||||
// Invalid IDN
|
||||
TestParser.TestSpec("[foo](http://ünicode..com)", "<p><a href=\"http://%C3%BCnicode..com\">foo</a></p>");
|
||||
}
|
||||
|
||||
[TestCase("link [foo [bar]]")] // https://spec.commonmark.org/0.29/#example-508
|
||||
[TestCase("link [foo][bar]")]
|
||||
[TestCase("link [][foo][bar][]")]
|
||||
|
||||
@@ -242,7 +242,18 @@ namespace Markdig.Renderers
|
||||
|
||||
if (idnaEncodeDomain)
|
||||
{
|
||||
string domainName = IdnMapping.GetAscii(content, schemeOffset, endOfDomain - schemeOffset);
|
||||
string domainName;
|
||||
|
||||
try
|
||||
{
|
||||
domainName = IdnMapping.GetAscii(content, schemeOffset, endOfDomain - schemeOffset);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Not a valid IDN, fallback to non-punycode encoding
|
||||
WriteEscapeUrl(content, schemeOffset, content.Length);
|
||||
return this;
|
||||
}
|
||||
|
||||
// Escape the characters (see Commonmark example 327 and think of it with a non-ascii symbol)
|
||||
int previousPosition = 0;
|
||||
|
||||
Reference in New Issue
Block a user