diff options
author | Bret Johnson <bret.johnson@microsoft.com> | 2022-02-02 03:11:46 +0300 |
---|---|---|
committer | Bret Johnson <bret.johnson@microsoft.com> | 2022-02-02 03:16:22 +0300 |
commit | d56faa55376af6bee85876e24c44990905b2f760 (patch) | |
tree | e2c1bcc21f8cf291292d1ba7116ed35e9b205bae | |
parent | f4e700578e3d21aa8befca61aa841b2d8db275de (diff) |
Properly handle escaping of markup textdev/bretjohn/use-html-decoding
Previously, Xwt assumed that the platform (Gtk) handled
encoding/decoding of markup text that contains special
characters. GLib.Markup.EscapeText would do the escaping
and then Gtk itself would unescape when displayed.
Since we switched from the Gtk to the Cocoa backend, that
has two problems - GLib.Markup.EscapeText crashes if
Gtk isn't there and even if it does work, there's nothing on
the Cocoa side to unescape the text.
Instead we now handle all escaping/unescaping in a backend
independent way. WebUtility.HtmlEncode does the escaping
and cross platform Xwt markup parsing code does the match
WebUtility.HtmlDecode to unescape.
For this to fully work the Xwt change and VSMac change need
to both be present, but the VSMac update is the most important
as it removes the crash.
-rw-r--r-- | Xwt/Xwt/FormattedText.cs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/Xwt/Xwt/FormattedText.cs b/Xwt/Xwt/FormattedText.cs index c4f04073..f1120f48 100644 --- a/Xwt/Xwt/FormattedText.cs +++ b/Xwt/Xwt/FormattedText.cs @@ -28,6 +28,7 @@ using System.Collections.Generic; using Xwt.Drawing; using System.Text; using System.Globalization; +using System.Net; namespace Xwt { @@ -62,7 +63,7 @@ namespace Xwt int last = 0; int i = markup.IndexOf ('<'); while (i != -1) { - sb.Append (markup, last, i - last); + sb.Append (WebUtility.HtmlDecode (markup.Substring (last, i - last))); if (PushSpan (formatStack, markup, sb.Length, ref i)) { last = i; i = markup.IndexOf ('<', i); @@ -76,7 +77,7 @@ namespace Xwt last = i; i = markup.IndexOf ('<', i + 1); } - sb.Append (markup, last, markup.Length - last); + sb.Append (WebUtility.HtmlDecode (markup.Substring (last, markup.Length - last))); Text = sb.ToString (); } |