[geary/wip/781488-aliyun-greeting-error: 1/6] Fix HTML signatures that are single IMG tags not recognised as HTML.



commit c4b90fb3eeeebf7906b7b296fac495bba68ecbf8
Author: Michael James Gratton <mike vee net>
Date:   Sat Oct 28 16:50:14 2017 +1100

    Fix HTML signatures that are single IMG tags not recognised as HTML.
    
    * src/engine/util/util-html.vala (smart_escape): Don't bother attempting
      to match a pair of tags, just something that looks like an opening tag,
      since IMG is an empty element and it is valid to not have a closing
      slash in HTML. Also, closing tags in HTML are optional anwyay. Add some
      unit tests.

 src/engine/util/util-html.vala  |    2 +-
 test/engine/util-html-test.vala |   42 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletions(-)
---
diff --git a/src/engine/util/util-html.vala b/src/engine/util/util-html.vala
index 8114f03..5eb45ab 100644
--- a/src/engine/util/util-html.vala
+++ b/src/engine/util/util-html.vala
@@ -176,7 +176,7 @@ public string smart_escape(string? text, bool preserve_whitespace_in_html) {
         return text;
 
     string res = text;
-    if (!Regex.match_simple("<([A-Z]*)(?: [^>]*)?>.*</(\\1)>|<[A-Z]*(?: [^>]*)?/>", res,
+    if (!Regex.match_simple("<[A-Z]*(?: [^>]*)?\\/?>", res,
                             RegexCompileFlags.CASELESS)) {
         res = Geary.HTML.escape_markup(res);
         preserve_whitespace_in_html = true;
diff --git a/test/engine/util-html-test.vala b/test/engine/util-html-test.vala
index 7a1df40..3eb25de 100644
--- a/test/engine/util-html-test.vala
+++ b/test/engine/util-html-test.vala
@@ -9,9 +9,51 @@ class Geary.HTML.UtilTest : Gee.TestCase {
 
     public UtilTest() {
         base("Geary.HTML.Util");
+        add_test("smart_escape_div", smart_escape_div);
+        add_test("smart_escape_no_closing_tag", smart_escape_no_closing_tag);
+        add_test("smart_escape_img", smart_escape_img);
+        add_test("smart_escape_xhtml_img", smart_escape_xhtml_img);
+        add_test("smart_escape_mixed", smart_escape_mixed);
+        add_test("smart_escape_text", smart_escape_text);
+        add_test("smart_escape_text_url", smart_escape_text_url);
         add_test("remove_html_tags", remove_html_tags);
     }
 
+    public void smart_escape_div() {
+        string html = "<div>ohhai</div>";
+        assert(Geary.HTML.smart_escape(html, false) == html);
+    }
+
+    public void smart_escape_no_closing_tag() {
+        string html = "<div>ohhai";
+        assert(Geary.HTML.smart_escape(html, false) == html);
+    }
+
+    public void smart_escape_img() {
+        string html = "<img src=\"http://example.com/lol.gif\";>";
+        assert(Geary.HTML.smart_escape(html, false) == html);
+    }
+
+    public void smart_escape_xhtml_img() {
+        string html = "<img src=\"http://example.com/lol.gif\"/>";
+        assert(Geary.HTML.smart_escape(html, false) == html);
+    }
+
+    public void smart_escape_mixed() {
+        string html = "mixed <div>ohhai</div> text";
+        assert(Geary.HTML.smart_escape(html, false) == html);
+    }
+
+    public void smart_escape_text() {
+        string text = "some text";
+        assert(Geary.HTML.smart_escape(text, false) == "<div style='white-space: pre;'>some text</div>");
+    }
+
+    public void smart_escape_text_url() {
+        string text = "<http://example.com>";
+        assert(Geary.HTML.smart_escape(text, false) == "<div style='white-space: 
pre;'>&lt;http://example.com&gt;</div>");
+    }
+
     public void remove_html_tags() {
         string blockquote_body = """<blockquote>hello</blockquote> <p>there</p>""";
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]