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.
This commit is contained in:
parent
5e55587e6d
commit
2a9f749145
2 changed files with 43 additions and 1 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;'><http://example.com></div>");
|
||||
}
|
||||
|
||||
public void remove_html_tags() {
|
||||
string blockquote_body = """<blockquote>hello</blockquote> <p>there</p>""";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue