[Xfce4-commits] <postler:master> Spilt multiple addresses separated by comma
Christian Dywan
noreply at xfce.org
Sat Jun 26 03:22:08 CEST 2010
Updating branch refs/heads/master
to a3a59352d800c97bf9515f3a8db27ed4f59eefb7 (commit)
from 5b1025bd6546b53c39c202e427f9abdb658b5bdc (commit)
commit a3a59352d800c97bf9515f3a8db27ed4f59eefb7
Author: Christian Dywan <christian at twotoasts.de>
Date: Tue Jun 22 21:35:31 2010 +0200
Spilt multiple addresses separated by comma
Make sure parse_address always returns a string vector
even in case of error, otherwise unexpected input can crash.
postler/postler-content.vala | 24 ++++++++++++++++--------
postler/postler-messages.vala | 6 +++++-
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index fda1192..d036da1 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -108,15 +108,23 @@ public class Postler.Content : WebKit.WebView {
.replace ("<", "<").replace (">", ">");
}
- internal static string linkify_address (string address, string? arguments)
+ internal static string linkify_address (string addresses, string? arguments)
requires (arguments == null || !arguments.contains ("<")) {
- string[] parsed = Postler.Messages.parse_address (address);
- string name = parsed[0];
- string cleaned = parsed[1];
- string quoted = html_escape (cleaned);
- string original = html_escape (address);
- return "<a href=\"" + quoted + (arguments != null ? arguments : "") +
- "\" title=\"" + original + "\">" + name + "</a>";
+ var linkified = new StringBuilder ();
+ foreach (string address in addresses.split (",")) {
+ if (address == "")
+ continue;
+ string[] parsed = Postler.Messages.parse_address (address);
+ string name = parsed[0];
+ string cleaned = parsed[1];
+ string quoted = html_escape (cleaned);
+ string original = html_escape (address);
+ if (linkified.len > 0)
+ linkified.append (", ");
+ linkified.append ("<a href=\"" + quoted + (arguments != null ? arguments : "") +
+ "\" title=\"" + original + "\">" + name + "</a>");
+ }
+ return linkified.str;
}
void populate_menu (Gtk.Menu menu) {
diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index 7f6eab3..ec1a06a 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -281,8 +281,12 @@ public class Postler.Messages : Gtk.TreeView {
}
internal static string[] parse_address (string address)
- requires (address.length > 0)
ensures (result[0] != null && result[1] != null) {
+ if (address.length < 1) {
+ GLib.critical ("parse_address: assertion '!address.length < 1' failed");
+ return { address, address };
+ }
+
if (!(">" in address && "<" in address))
return { address, address };
More information about the Xfce4-commits
mailing list