Skip to content

Commit 67340a3

Browse files
committed
Defensive code with relative img
1 parent e642278 commit 67340a3

File tree

3 files changed

+201
-188
lines changed

3 files changed

+201
-188
lines changed

src/Html2OpenXml/IO/DefaultWebRequest.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,17 @@ public DefaultWebRequest(HttpClient httpClient, ILogger? logger = null)
6363
requestUri = UrlCombine(BaseImageUrl, requestUri.OriginalString);
6464
}
6565

66-
if (requestUri.IsFile)
66+
bool isLocalFile;
67+
try
68+
{
69+
isLocalFile = requestUri.IsFile;
70+
}
71+
catch (InvalidOperationException)
72+
{
73+
isLocalFile = false;
74+
}
75+
76+
if (isLocalFile)
6777
{
6878
return DownloadLocalFile(requestUri, cancellationToken);
6979
}
@@ -108,6 +118,9 @@ public DefaultWebRequest(HttpClient httpClient, ILogger? logger = null)
108118
{
109119
logger?.LogDebug("Downloading remote file: {0}", requestUri);
110120

121+
if (httpClient.BaseAddress is null && !requestUri.IsAbsoluteUri)
122+
return null;
123+
111124
var response = await httpClient.GetAsync(requestUri, cancellationToken).ConfigureAwait(false);
112125
if (response == null) return null;
113126
resource.StatusCode = response.StatusCode;

0 commit comments

Comments
 (0)