diff --git a/Source/HtmlRenderer/Core/Parse/RegexParserUtils.cs b/Source/HtmlRenderer/Core/Parse/RegexParserUtils.cs
index 806fca4cf..64e2891d9 100644
--- a/Source/HtmlRenderer/Core/Parse/RegexParserUtils.cs
+++ b/Source/HtmlRenderer/Core/Parse/RegexParserUtils.cs
@@ -107,9 +107,9 @@ public static string GetCssAtRules(string stylesheet, ref int startIdx)
int endIdx = stylesheet.IndexOf('{', startIdx);
if (endIdx > -1)
{
+ endIdx++; // to prevent IndexOutOfRangeException at line 113. When '}' is last character in 'stylesheet' variable
while (count > 0 && endIdx < stylesheet.Length)
{
- endIdx++;
if (stylesheet[endIdx] == '{')
{
count++;
@@ -118,6 +118,7 @@ public static string GetCssAtRules(string stylesheet, ref int startIdx)
{
count--;
}
+ endIdx++;
}
if (endIdx < stylesheet.Length)
{
@@ -194,4 +195,4 @@ private static Regex GetRegex(string regex)
return r;
}
}
-}
\ No newline at end of file
+}