Skip to content

Commit

Permalink
Trap for URI format exceptions when unescaping URLs. Use raw base val…
Browse files Browse the repository at this point in the history
…ue in

the event of errors.
  • Loading branch information
Kinematics committed Jun 11, 2017
1 parent 91a74cb commit ccd491a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions NetTally.Core/Input/Forums/PostText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,23 @@ private static StringBuilder ExtractPostTextString(HtmlNode node, Predicate<Html
if (child.GetAttributeValue("class", "").Contains("mceSmilieSprite"))
break;

string imgHref = srcUrl;

if (!string.IsNullOrEmpty(srcUrl))
{
// If the source URL is relative, prepend the forum's host.
// This will not modify absolute URLs.
Uri absoluteSrc = new Uri(host, Uri.UnescapeDataString(srcUrl));

sb.Append($"『url=\"{absoluteSrc.ToString()}\"』<Image>『/url』");
try
{
// If the source URL is relative, prepend the forum's host.
// This will not modify absolute URLs.
Uri absoluteSrc = new Uri(host, Uri.UnescapeDataString(srcUrl));
imgHref = absoluteSrc.ToString();
}
catch (UriFormatException)
{
}
}

sb.Append($"『url=\"{imgHref}\"』<Image>『/url』");
break;
case "div":
// Recurse into divs (typically spoilers).
Expand Down

0 comments on commit ccd491a

Please sign in to comment.