Skip to content

Commit 4699de7

Browse files
author
ArthurHub
committed
* Fix breaking urls when loading downloaded stylesheet
1 parent e578769 commit 4699de7

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎Source/HtmlRenderer/Handlers/StylesheetLoadHandler.cs‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,19 @@ private static string LoadStylesheetFromUri(HtmlContainer htmlContainer, Uri uri
153153
private static string CorrectRelativeUrls(string stylesheet, Uri baseUri)
154154
{
155155
int idx = 0;
156-
while( idx != -1 && idx < stylesheet.Length )
156+
while (idx != -1 && idx < stylesheet.Length)
157157
{
158158
idx = stylesheet.IndexOf("url", idx, StringComparison.OrdinalIgnoreCase);
159-
if( idx > 0 )
159+
if (idx > 0)
160160
{
161161
int endIdx = stylesheet.IndexOf(")", idx, StringComparison.OrdinalIgnoreCase);
162-
if( endIdx > 0 )
162+
if (endIdx > 0)
163163
{
164-
var urlStr = stylesheet.Substring(idx + 4, endIdx - idx - 4);
164+
var offset1 = 4 + (stylesheet[idx + 4] == '\'' ? 1 : 0);
165+
var offset2 = (stylesheet[endIdx - 1] == '\'' ? 1 : 0);
166+
var urlStr = stylesheet.Substring(idx + offset1, endIdx - idx - offset1 - offset2);
165167
Uri url;
166-
if( Uri.TryCreate(urlStr, UriKind.Relative, out url) )
168+
if (Uri.TryCreate(urlStr, UriKind.Relative, out url))
167169
{
168170
url = new Uri(baseUri, url);
169171
stylesheet = stylesheet.Remove(idx + 4, endIdx - idx - 4);

0 commit comments

Comments
 (0)