Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c6b3929

Browse files
author
Jeroen Diederix
committed
Convert code points from other unicode planes to utf16, like emoticons 😃, and avoid a hard unhandled exception.
1 parent 9aafeeb commit c6b3929

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Source/HtmlRenderer/Core/Utils/HtmlUtils.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,12 @@ private static string DecodeHtmlCharByCode(string str)
370370
num = num * (hex ? 16 : 10) + CommonUtils.ToDigit(str[endIdx++], hex);
371371
endIdx += (endIdx < str.Length && str[endIdx] == ';') ? 1 : 0;
372372

373+
string repl = string.Empty;
374+
if (num >= 0 && num <= 0x10ffff && !(num >= 0xd800 && num <= 0xdfff))
375+
repl = Char.ConvertFromUtf32((int)num);
376+
373377
str = str.Remove(idx, endIdx - idx);
374-
str = str.Insert(idx, Convert.ToChar(num).ToString());
378+
str = str.Insert(idx, repl);
375379

376380
idx = str.IndexOf("&#", idx + 1);
377381
}

0 commit comments

Comments
 (0)