Skip to content

Commit dfa7469

Browse files
committed
Merge pull request #112 from dotmailer/master
Fix for occasional crash due to unsupported URI schemes
2 parents 1610946 + 0334ea0 commit dfa7469

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

PreMailer.Net/PreMailer.Net.Tests/LinkTagCssSourceTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ public void GetCSS_AbsoluteUrlInHref_CallsWebDownloader_WithSpecifiedPath()
6969
_webDownloader.Verify(w => w.DownloadString(new Uri(path)));
7070
}
7171

72+
[TestMethod]
73+
public void GetCSS_DoesNotCallWebDownloader_WhenSchemeNotSupported()
74+
{
75+
string path = "chrome-extension://fcdjadjbdihbaodagojiomdljhjhjfho/css/atd.css";
76+
77+
LinkTagCssSource sut = CreateSUT(path: path);
78+
sut.GetCss();
79+
80+
_webDownloader.Verify(w => w.DownloadString(new Uri(path)), Times.Never);
81+
}
82+
7283
private LinkTagCssSource CreateSUT(string baseUrl = "http://a.com", string path = "a.css", string link = "<link href=\"{0}\" />")
7384
{
7485
var node = new HtmlParser().Parse(String.Format(link, path));

PreMailer.Net/PreMailer.Net/Sources/LinkTagCssSource.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,20 @@ public LinkTagCssSource(IElement node, Uri baseUri)
2828

2929
public string GetCss()
3030
{
31-
return _cssContents ?? (_cssContents = WebDownloader.SharedDownloader.DownloadString(_downloadUri));
31+
if (IsSupported(_downloadUri.Scheme))
32+
{
33+
return _cssContents ?? (_cssContents = WebDownloader.SharedDownloader.DownloadString(_downloadUri));
34+
}
35+
return string.Empty;
36+
}
37+
38+
private bool IsSupported(string scheme)
39+
{
40+
return
41+
scheme == Uri.UriSchemeHttp ||
42+
scheme == Uri.UriSchemeHttps ||
43+
scheme == Uri.UriSchemeFtp ||
44+
scheme == Uri.UriSchemeFile;
3245
}
3346
}
3447
}

0 commit comments

Comments
 (0)