From 223603393b12594b1d036ae129ff14b4671961d5 Mon Sep 17 00:00:00 2001 From: eleksir Date: Sun, 30 Oct 2016 22:36:13 +0300 Subject: [PATCH] properly escape notify text body, now all messages should be shown --- notifications.pl | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/notifications.pl b/notifications.pl index 0e9bac1..36abbbf 100644 --- a/notifications.pl +++ b/notifications.pl @@ -14,6 +14,7 @@ sub hookfn; sub freehooks; sub timeraction; sub notify_cmd; +sub encodestr; my $script_name = "Notification plugin"; my $help = 'Usage: @@ -25,7 +26,7 @@ my $help = 'Usage: /notify show - shows whitelists and their statuses '; -register($script_name, '0.8.5', 'Sends *nix desktop notifications', \&freehooks); +register($script_name, '0.9', 'Sends *nix desktop notifications', \&freehooks); HexChat::print("$script_name loaded\n"); my @hooks; @@ -120,7 +121,12 @@ sub hookfn { sub notify(@) { my($channel, $nick, $text) = @_; +# notify-send|notification daemons are use limited html formatting for message body, so we have +# either use only topic without body or encode message body, which is a bit resource hungry HexChat::strip_code($text); + HexChat::strip_code($nick); + $text = encodestr($text); + $nick = encodestr($nick); my $topic = sprintf("%s at %s says:\n", $nick, $channel); system("notify-send", "-u", "normal", "-t", "12000", "-a", "hexchat", $topic, "-i", "hexchat", $text); undef $channel, undef $nick, undef $text; undef $topic; @@ -371,3 +377,16 @@ sub freehooks { return HexChat::EAT_ALL; } + +sub encodestr { + my $str = shift; + $str = join('', map { + if ($_ eq '<') { $_ = '<'; } + elsif ($_ eq '>') { $_ = '>'; } + elsif ($_ eq '&') { $_ = '&'; } + elsif ($_ eq '"') { $_ = '"'} + else { $_ = $_; } + } split(//, $str)); + + return $str; +}