[geary] Stricter regex for finding HTML tags
- From: Robert Schroll <rschroll src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary] Stricter regex for finding HTML tags
- Date: Tue, 3 Feb 2015 22:40:12 +0000 (UTC)
commit 3d14719aa0208e6c552146f0467005577deffb76
Author: Robert Schroll <rschroll gmail com>
Date: Tue Feb 3 00:19:12 2015 -0500
Stricter regex for finding HTML tags
This function is moved from the client to the engine, since it is
somewhat specialized.
https://bugzilla.gnome.org/show_bug.cgi?id=743898
src/client/accounts/add-edit-page.vala | 2 +-
src/client/composer/composer-widget.vala | 4 ++--
src/client/util/util-webkit.vala | 17 +++++++++++++++++
src/engine/util/util-html.vala | 15 ---------------
4 files changed, 20 insertions(+), 18 deletions(-)
---
diff --git a/src/client/accounts/add-edit-page.vala b/src/client/accounts/add-edit-page.vala
index a78d5df..650098a 100644
--- a/src/client/accounts/add-edit-page.vala
+++ b/src/client/accounts/add-edit-page.vala
@@ -581,7 +581,7 @@ public class AddEditPage : Gtk.Box {
private void on_signature_stack_changed() {
if (signature_stack.visible_child_name == "preview_window")
- preview_webview.load_html_string(Geary.HTML.smart_escape(email_signature, true), "");
+ preview_webview.load_html_string(smart_escape(email_signature, true), "");
}
private uint16 get_default_smtp_port() {
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 459557e..9626b2f 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -993,7 +993,7 @@ public class ComposerWidget : Gtk.EventBox {
set_cursor();
return;
}
- signature = Geary.HTML.smart_escape(signature, false);
+ signature = smart_escape(signature, false);
} catch (Error error) {
debug("Error reading signature file %s: %s", signature_file.get_path(), error.message);
set_cursor();
@@ -1005,7 +1005,7 @@ public class ComposerWidget : Gtk.EventBox {
set_cursor();
return;
}
- signature = Geary.HTML.smart_escape(signature, true);
+ signature = smart_escape(signature, true);
}
if (body_html == null)
diff --git a/src/client/util/util-webkit.vala b/src/client/util/util-webkit.vala
index d870388..fd06773 100644
--- a/src/client/util/util-webkit.vala
+++ b/src/client/util/util-webkit.vala
@@ -467,3 +467,20 @@ public bool dissasemble_data_uri(string uri, out Geary.Memory.Buffer? buffer) {
return true;
}
+// Escape reserved HTML entities if the string does not have HTML tags. If there are no tags,
+// or if preserve_whitespace_in_html is true, wrap the string a div to preserve whitespace.
+public string smart_escape(string? text, bool preserve_whitespace_in_html) {
+ if (text == null)
+ return text;
+
+ string res = text;
+ if (!Regex.match_simple("<([A-Z]*)(?: [^>]*)?>.*</(\\1)>|<[A-Z]*(?: [^>]*)?/>", res,
+ RegexCompileFlags.CASELESS)) {
+ res = Geary.HTML.escape_markup(res);
+ preserve_whitespace_in_html = true;
+ }
+ if (preserve_whitespace_in_html)
+ res = @"<div style='white-space: pre;'>$res</div>";
+ return res;
+}
+
diff --git a/src/engine/util/util-html.vala b/src/engine/util/util-html.vala
index 561c9d9..ce34ec5 100644
--- a/src/engine/util/util-html.vala
+++ b/src/engine/util/util-html.vala
@@ -88,21 +88,6 @@ public string preserve_whitespace(string? text) {
return output;
}
-public string smart_escape(string? text, bool preserve_whitespace_in_html) {
- if (text == null)
- return text;
-
- string res = text;
- if (!Regex.match_simple("<([A-Z]*)[^>]*>.*</(\\1)>|<[^>]*/>", res,
- RegexCompileFlags.CASELESS)) {
- res = escape_markup(res);
- preserve_whitespace_in_html = true;
- }
- if (preserve_whitespace_in_html)
- res = @"<div style='white-space: pre;'>$res</div>";
- return res;
-}
-
// Removes any text between < and >. Additionally, if input terminates in the middle of a tag,
// the tag will be removed.
// If the HTML is invalid, the original string will be returned.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]