Merge with default experimental_untrusted
authorThomas
Fri, 05 Oct 2018 14:27:16 +0200
branchexperimental_untrusted
changeset 23921644bf72b1d9
parent 2390 2567ecbe949c
parent 2387 f3255f949ddf
child 2397 6c3c90d4275e
Merge with default
UI/FormControlPreviewMessage.xaml.cs
     1.1 --- a/UI/FormControlPreviewMessage.xaml.cs	Fri Oct 05 14:25:57 2018 +0200
     1.2 +++ b/UI/FormControlPreviewMessage.xaml.cs	Fri Oct 05 14:27:16 2018 +0200
     1.3 @@ -174,14 +174,21 @@
     1.4                  try
     1.5                  {
     1.6                      Match m = Regex.Match(htmlString, @"<head(.+?)</head>|<head(.+?)<meta(.+?)content-type(.+?)>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
     1.7 -                    if (m.Value?.Contains("charset=") == true)
     1.8 +                    string head = m.Value;
     1.9 +
    1.10 +                    // Check if head already contains a charset
    1.11 +                    if (string.IsNullOrEmpty(Regex.Match(head, "charset=", RegexOptions.Singleline | RegexOptions.IgnoreCase)?.Value) == false)
    1.12                      {
    1.13 -                        string utf8 = Regex.Replace(m.Value, "charset=(.+)'", "charset='utf-8'", RegexOptions.Singleline | RegexOptions.IgnoreCase);
    1.14 -                        Regex r = new Regex(".*", RegexOptions.IgnoreCase);
    1.15 -                        htmlString = r.Replace(htmlString, utf8, 1);
    1.16 +                        // If charset is not yet UTF-8, change it
    1.17 +                        if (string.IsNullOrEmpty(Regex.Match(head, "charset='utf-8'", RegexOptions.IgnoreCase)?.Value))
    1.18 +                        {
    1.19 +                            string utf8 = Regex.Replace(m.Value, "charset=(.+)'", "charset='utf-8'", RegexOptions.Singleline | RegexOptions.IgnoreCase);
    1.20 +                            htmlString = Regex.Replace(htmlString, m.Value, utf8);
    1.21 +                        }
    1.22                      }
    1.23                      else
    1.24                      {
    1.25 +                        // Otherwise, add it
    1.26                          Regex r = new Regex("<head(.*?)>", RegexOptions.IgnoreCase);
    1.27                          Match m2 = r.Match(htmlString);
    1.28                          if (string.IsNullOrEmpty(m2.Value))