<br /> issues

Apr 7, 2014 at 10:10 AM
Hello.

There is exception when HTML text contains
<br />
Any ideas?

Stack trace:
System.IndexOutOfRangeException: Index was outside the bounds of the array.

   at HtmlRenderer.Parse.HtmlParser.ExtractAttributes(String source, Int32 idx, Int32 length, Dictionary`2& attributes) in HtmlRenderer 1.4.13.0\Source\HtmlRenderer\Parse\HtmlParser.cs:line 220

   at HtmlRenderer.Parse.HtmlParser.ParseHtmlTag(String source, Int32 idx, Int32 length, String& name, Dictionary`2& attributes) in HtmlRenderer 1.4.13.0\Source\HtmlRenderer\Parse\HtmlParser.cs:line 186

   at HtmlRenderer.Parse.HtmlParser.ParseHtmlTag(String source, Int32 tagIdx, CssBox& curBox) in HtmlRenderer 1.4.13.0\Source\HtmlRenderer\Parse\HtmlParser.cs:line 120

   at HtmlRenderer.Parse.HtmlParser.ParseDocument(String source) in HtmlRenderer 1.4.13.0\Source\HtmlRenderer\Parse\HtmlParser.cs:line 63

   at HtmlRenderer.Parse.DomParser.GenerateCssTree(String html, HtmlContainer htmlContainer, CssData& cssData) in HtmlRenderer 1.4.13.0\Source\HtmlRenderer\Parse\DomParser.cs:line 37
.........
Apr 7, 2014 at 11:15 AM
Fast & dirty fix (did not tested properly).

In HtmlParser.cs go to method
private static bool ParseHtmlTag(string source, int idx, int length, out string name, out Dictionary<string, string> attributes)
Then go to code:
            attributes = null;
            if (!isClosing && idx + length > spaceIdx)
            {
                ExtractAttributes(source, spaceIdx, length - (spaceIdx - idx), out attributes);
            }

            return isClosing;
Replace to:
            var remainingPart = source.Length >= spaceIdx + 1 ? source.Substring(spaceIdx) : string.Empty;
            bool closedImmediately = string.IsNullOrEmpty(remainingPart) || remainingPart.Trim().StartsWith("/");

            attributes = null;
            if (!isClosing && idx + length > spaceIdx && !closedImmediately)
            {
                ExtractAttributes(source, spaceIdx, length - (spaceIdx - idx), out attributes);
            }

            return isClosing;
Developer
Apr 7, 2014 at 4:20 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.