From unknown Mon Jun 16 23:32:30 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#43328 <43328@debbugs.gnu.org> To: bug#43328 <43328@debbugs.gnu.org> Subject: Status: [PATCH] Make ERC desktop notifications lenient to invalid XML Reply-To: bug#43328 <43328@debbugs.gnu.org> Date: Tue, 17 Jun 2025 06:32:30 +0000 retitle 43328 [PATCH] Make ERC desktop notifications lenient to invalid XML reassign 43328 emacs submitter 43328 Dario Gjorgjevski severity 43328 normal tag 43328 fixed patch thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Sep 11 05:42:03 2020 Received: (at submit) by debbugs.gnu.org; 11 Sep 2020 09:42:03 +0000 Received: from localhost ([127.0.0.1]:42330 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kGfZD-0003s6-6Z for submit@debbugs.gnu.org; Fri, 11 Sep 2020 05:42:03 -0400 Received: from lists.gnu.org ([209.51.188.17]:49604) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kGfZB-0003rm-HS for submit@debbugs.gnu.org; Fri, 11 Sep 2020 05:42:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kGfZB-0002C8-AY for bug-gnu-emacs@gnu.org; Fri, 11 Sep 2020 05:42:01 -0400 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]:46613) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kGfZ9-00023O-88 for bug-gnu-emacs@gnu.org; Fri, 11 Sep 2020 05:42:00 -0400 Received: by mail-ed1-x530.google.com with SMTP id a12so9254806eds.13 for ; Fri, 11 Sep 2020 02:41:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=u8FROfqY2W+Cd3EZSaBinAPbpJ8Ej/pWeecvLJh60b8=; b=RxbjEey3hpKJVuS+qxAm1dWGRZ4H9y6SCC9qJ9MLpwGgtBIn5xpsXmw4NE9ZrfEEuG BD3DKIhptSmA/t1ndysPyASzeSqc9DFfMOZkwhhsw9Oq2ESpjWUFd6jEhikeGeohXcAQ Q3S56014I0jas9wgxHDiAA767cdgc/1XJ9xwIhVhzyU71M4XDyHsNhNzwa6Qp6x3VtDM 8WPJ6VF3DgnQDP5GYlsBIcz8D00CSebdLByGEj9JwT3UBCs2KG0gyOZ8thLBdaJAc2QR 4QoxuetXwAloX9WUoaSHqsNAiKqnaw8bTIhYn9avGV+WjZ1l0oxnkRibnUdAZv5VjncH ODsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=u8FROfqY2W+Cd3EZSaBinAPbpJ8Ej/pWeecvLJh60b8=; b=ZZe3gYejR3t2gPyYXSP5HN+sK9S0gBxif3B89pqlKkLeY+z0smHwCwPMbWugUOjISu c0k0hXHMj/ehpX8Q2OX9E7NueO4tF7RaILejVebU5hwIzjaeKrNpUiQYvVVWFweOXY/6 TVgG3VM6viRfOb6V7uhZWlwfA1Sm5oYOr4Y/adUWWm8VP3Ru7BAkd50yuZGsz+58P11g KLgjZuY+fzsdeJV0JLXJW1ZB8JI14pfUupF6m0K/ikDY5UCpFpuVFhuxYS6aw92pylFZ rM2gxd8ATWf+zRW79+GrMKTeDpV2bfJzpUQ7YHAeNxBwAgJhLCrlmdO+EZg47HiO/9/o JSmw== X-Gm-Message-State: AOAM533s2ru6pqt5nzEM0js/o28roMItJI6+Ach8befEyzUnTGjRDdtM wA/A2XRleOY4Yfz66MJOrtHVAXlX9GlgJQ== X-Google-Smtp-Source: ABdhPJzIfYeOZmVE0gQWk3OI6NIJumtvf3i13eWmEw+GqGqoFYwMqKhHCjW/dgwXAJGRG16pl7Kv4g== X-Received: by 2002:a50:f687:: with SMTP id d7mr1097362edn.353.1599817317251; Fri, 11 Sep 2020 02:41:57 -0700 (PDT) Received: from ZALANDO-31298 ([79.140.114.32]) by smtp.gmail.com with ESMTPSA id gw6sm1209114ejb.47.2020.09.11.02.41.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Sep 2020 02:41:55 -0700 (PDT) From: Dario Gjorgjevski To: bug-gnu-emacs@gnu.org Subject: [PATCH] Make ERC desktop notifications lenient to invalid XML Date: Fri, 11 Sep 2020 11:41:54 +0200 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::530; envelope-from=dario.gjorgjevski@gmail.com; helo=mail-ed1-x530.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.7 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, Currently, =E2=80=98erc-notifications-notify=E2=80=99 signals an error if t= he message contains invalid XML characters. These characters can be either either IRC control codes (e.g., ^B for bold text or ^C6,12 for colored text) or just plain invalid data. This patch changes the behavior so that they are stripped instead. To test, try sending yourself a message such as /msg ^BHi! where is your own nick. The current version will signal an error whereas this patch won=E2=80=99t. The proposed patch is attached to this message. --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename=0001-Make-ERC-desktop-notifications-lenient-to-invalid-XM.patch Content-Transfer-Encoding: quoted-printable Content-Description: Make ERC desktop notifications lenient to invalid XML >From ad376fafc7b453fe8f34dbdb2a8d60b7757d6edd Mon Sep 17 00:00:00 2001 From: Dario Gjorgjevski Date: Fri, 11 Sep 2020 11:26:17 +0200 Subject: [PATCH] Make ERC desktop notifications lenient to invalid XML characters MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit Currently, =E2=80=98erc-notifications-notify=E2=80=99 signals an error if t= he message contains invalid XML characters. These characters can be either either IRC control codes (e.g., ^B for bold text or ^C6,12 for colored text) or just plain invalid data. This commit changes the behavior so that they are stripped instead. To test, try sending yourself a message such as /msg ^BHi! where is your own nick. The current version will signal an error whereas this commit won=E2=80=99t. * lisp/xml.el (xml-invalid-characters-re): New constant. (xml-escape-string): New optional parameter NOERROR, causing invalid characters to be stripped instead of signaling an error. * lisp/erc/erc-desktop-notifications.el (erc-notifications-notify): Strip IRC control codes and invalid XML characters before notifying. --- lisp/erc/erc-desktop-notifications.el | 11 ++++++----- lisp/xml.el | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lisp/erc/erc-desktop-notifications.el b/lisp/erc/erc-desktop-n= otifications.el index 1e65f8f427..3a9a4a4bac 100644 --- a/lisp/erc/erc-desktop-notifications.el +++ b/lisp/erc/erc-desktop-notifications.el @@ -31,6 +31,7 @@ (require 'erc) (require 'xml) (require 'notifications) +(require 'erc-goodies) (require 'erc-match) (require 'dbus) =20 @@ -62,12 +63,12 @@ This will replace the last notification sent with this = function." ;; setting the current buffer to the existing query buffer) (dbus-ignore-errors (setq erc-notifications-last-notification - (let ((channel (if privp (erc-get-buffer nick) (current-buffer))= )) + (let* ((channel (if privp (erc-get-buffer nick) (current-buffer)= )) + (title (format "%s in %s" (xml-escape-string nick t) chan= nel)) + (body (xml-escape-string (erc-controls-strip msg) t))) (notifications-notify :bus erc-notifications-bus - :title (format "%s in %s" - (xml-escape-string nick) - channel) - :body (xml-escape-string msg) + :title title + :body body :replaces-id erc-notifications-last-noti= fication :app-icon erc-notifications-icon :actions '("default" "Switch to buffer") diff --git a/lisp/xml.el b/lisp/xml.el index 10ef8e2087..236d9cbe6c 100644 --- a/lisp/xml.el +++ b/lisp/xml.el @@ -1015,7 +1015,10 @@ The first line is indented with the optional INDENT-= STRING." =20 (defalias 'xml-print 'xml-debug-print) =20 -(defun xml-escape-string (string) +(defconst xml-invalid-characters-re + "[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\U00010000-\U0010FFFF]") + +(defun xml-escape-string (string &optional noerror) "Convert STRING into a string containing valid XML character data. Replace occurrences of &<>\\=3D'\" in STRING with their default XML entity references (e.g., replace each & with &). @@ -1026,15 +1029,17 @@ restriction on \" or \\=3D', but we just substitute= for these too \(as is permitted by the spec). =20 If STRING contains characters that are invalid in XML (as defined -by https://www.w3.org/TR/xml/#charsets), signal an error of type -`xml-invalid-character'." +by https://www.w3.org/TR/xml/#charsets), operate depending on the +value of NOERROR: if it is non-nil, remove them; else, signal an +error of type `xml-invalid-character'." (with-temp-buffer (insert string) (goto-char (point-min)) - (when (re-search-forward - "[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\U00010000-\U001= 0FFFF]" - nil t) - (signal 'xml-invalid-character (list (char-before) (match-beginning = 0)))) + (while (re-search-forward xml-invalid-characters-re nil t) + (if noerror + (replace-match "") + (signal 'xml-invalid-character + (list (char-before) (match-beginning 0))))) (dolist (substitution '(("&" . "&") ("<" . "<") (">" . ">") --=20 2.17.1 --=-=-= Content-Type: text/plain Best regards, Dario -- dario.gjorgjevski@gmail.com :: +49 1525 8666837 % gpg --keyserver 'hkps://hkps.pool.sks-keyservers.net' \ \`> --recv-keys '744A4F0B4F1C9371' --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu Oct 15 11:49:24 2020 Received: (at 43328) by debbugs.gnu.org; 15 Oct 2020 15:49:24 +0000 Received: from localhost ([127.0.0.1]:56289 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kT5VM-0007iR-Hg for submit@debbugs.gnu.org; Thu, 15 Oct 2020 11:49:24 -0400 Received: from quimby.gnus.org ([95.216.78.240]:44672) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kT5VJ-0007hz-Gy for 43328@debbugs.gnu.org; Thu, 15 Oct 2020 11:49:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=WQym18Ieas7liXvUF5MP6xNTTlDoaHrY5fByEQtj3mA=; b=mqWq366DvpAJCaDUs2mVyuLkGA SY1Oy8As+73q4aHsIFFdTjxfP/Lqt0WX+DFc5Tx7XnCT5w4T/BPBFgN2vgCFaPZShnrezRAZ80bfh Gbp1S1yU3Mh1iFTqveGCB3PDMjmQLxI2LbPWUcdP6TxN1l+vHJ0FPRA62Uz3HmTFGdKY=; Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kT5VB-0005xz-4j; Thu, 15 Oct 2020 17:49:15 +0200 From: Lars Ingebrigtsen To: Dario Gjorgjevski Subject: Re: bug#43328: [PATCH] Make ERC desktop notifications lenient to invalid XML References: X-Now-Playing: Hood's _Photographers_: "Winter Will Set You Back" Date: Thu, 15 Oct 2020 17:49:11 +0200 In-Reply-To: (Dario Gjorgjevski's message of "Fri, 11 Sep 2020 11:41:54 +0200") Message-ID: <878sc7v6a0.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: Dario Gjorgjevski writes: > The proposed patch is attached to this message. Looks like this patch was applied to Emacs 28 about a month ago, but apparently I neglected to tell the patch submitter. Sorry. Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 43328 Cc: 43328@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Dario Gjorgjevski writes: > The proposed patch is attached to this message. Looks like this patch was applied to Emacs 28 about a month ago, but apparently I neglected to tell the patch submitter. Sorry. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no From debbugs-submit-bounces@debbugs.gnu.org Thu Oct 15 11:49:28 2020 Received: (at control) by debbugs.gnu.org; 15 Oct 2020 15:49:28 +0000 Received: from localhost ([127.0.0.1]:56292 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kT5VP-0007ie-Os for submit@debbugs.gnu.org; Thu, 15 Oct 2020 11:49:28 -0400 Received: from quimby.gnus.org ([95.216.78.240]:44686) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kT5VO-0007iG-Pr for control@debbugs.gnu.org; Thu, 15 Oct 2020 11:49:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Subject:From:To:Message-Id:Date:Sender:Reply-To:Cc: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Nthx/0bJLug2eHTJFetpDUET86bnebzJiedBxE/JaQc=; b=giZx+iNoFBD1EqtgVaovaAtvq1 Q/nNQNYOR+TAKOL822sIW0cVPPbgmASzJPTld+wivckpVq5zlrX2iXCA3bzhoJJ9mgxInaB7kNeEO E+6kgOJ1ShGhvYf/QFcp39nWt9woWm5ibSGu7/Jdx9hg/vYVdMH37tlwEwR/W6SvbmyA=; Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kT5VG-0005y8-Vh for control@debbugs.gnu.org; Thu, 15 Oct 2020 17:49:21 +0200 Date: Thu, 15 Oct 2020 17:49:17 +0200 Message-Id: <877drrv69u.fsf@gnus.org> To: control@debbugs.gnu.org From: Lars Ingebrigtsen Subject: control message for bug #43328 X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: tags 43328 fixed close 43328 28.1 quit Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) tags 43328 fixed close 43328 28.1 quit From unknown Mon Jun 16 23:32:30 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Fri, 13 Nov 2020 12:24:08 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator