Skip to content

Commit d90a97a

Browse files
authored
Merge pull request #27 from redwyre/master
Fix for the last attribute without a value crashing the parser
2 parents 0729edf + 369c2b0 commit d90a97a

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

Source/HtmlRenderer/Core/Parse/HtmlParser.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,27 +222,31 @@ private static void ExtractAttributes(string source, int idx, int length, out Di
222222
if (startIdx < idx + length)
223223
{
224224
var key = source.Substring(startIdx, endIdx - startIdx);
225+
var value = "";
225226

226227
startIdx = endIdx + 1;
227228
while (startIdx < idx + length && (char.IsWhiteSpace(source, startIdx) || source[startIdx] == '='))
228229
startIdx++;
229230

230231
bool hasPChar = false;
231-
char pChar = source[startIdx];
232-
if (pChar == '"' || pChar == '\'')
232+
if (startIdx < idx + length)
233233
{
234-
hasPChar = true;
235-
startIdx++;
236-
}
234+
char pChar = source[startIdx];
235+
if (pChar == '"' || pChar == '\'')
236+
{
237+
hasPChar = true;
238+
startIdx++;
239+
}
237240

238-
endIdx = startIdx + (hasPChar ? 0 : 1);
239-
while (endIdx < idx + length && (hasPChar ? source[endIdx] != pChar : !char.IsWhiteSpace(source, endIdx)))
240-
endIdx++;
241+
endIdx = startIdx + (hasPChar ? 0 : 1);
242+
while (endIdx < idx + length && (hasPChar ? source[endIdx] != pChar : !char.IsWhiteSpace(source, endIdx)))
243+
endIdx++;
241244

242-
var value = source.Substring(startIdx, endIdx - startIdx);
243-
value = HtmlUtils.DecodeHtml(value);
245+
value = source.Substring(startIdx, endIdx - startIdx);
246+
value = HtmlUtils.DecodeHtml(value);
247+
}
244248

245-
if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
249+
if (!string.IsNullOrEmpty(key) && (value != null))
246250
{
247251
if (attributes == null)
248252
attributes = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);

0 commit comments

Comments
 (0)