Crash in DecodeHtmlCharByCode

Mar 25, 2013 at 7:35 PM
String passed in: "Reserve&#34" (I believe &#34 is a double-quote)

Error: Index was outside the bounds of the array. (line 366, HtmlUtils.cs)

Fix: ? (still investigating)
Mar 25, 2013 at 8:09 PM
This appears to fix it. I don't THINK it has downstream implications, but it's working for me:
        private static string DecodeHtmlCharByCode(string str)
        {
            var idx = str.IndexOf("&#");
            while (idx > -1)
            {
                var endIdx = idx + 2;
                long num = 0;
                while (endIdx < str.Length && char.IsDigit(str[endIdx]))
                    num = num * 10 + str[endIdx++] - '0';
                endIdx += (endIdx < str.Length && str[endIdx] == ';') ? 1 : 0;

                str = str.Remove(idx, endIdx - idx);
                str = str.Insert(idx, Convert.ToChar(num).ToString());

                idx = str.IndexOf("&#", idx);
            }
            return str;
        }
Developer
Apr 4, 2013 at 4:34 PM
good fix, thx, i will add it to next release.