all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#71889: [PATCH] nnatom: Ensure some parsed values are one line
@ 2024-07-01 23:44 Daniel Semyonov via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-07-02 21:23 ` Daniel Semyonov via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Semyonov via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-07-01 23:44 UTC (permalink / raw)
  To: 71889

[-- Attachment #1: Type: text/plain, Size: 569 bytes --]

Tags: patch

Hi,

Attached is a patch which ensures some values parsed by nnatom from Atom
feeds only contain a single line of whitespace-trimmed text.

Daniel



In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.41, cairo version 1.18.0) of 2024-06-12 built on coldharbour
Repository revision: 3905db6e3aa947b847c072259ad6d08c8a15e10e
Repository branch: master
System Description: Void Linux

Configured using:
 'configure -C --prefix=/opt/Emacs --without-x --with-pgtk
 --with-small-ja-dic --with-native-compilation 'CFLAGS=-march=native
 -O2''


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-nnatom-Ensure-some-parsed-values-are-one-line.patch --]
[-- Type: text/patch, Size: 4836 bytes --]

From 3fa370de964dbbaa89b4cce5baa0602951dabfcf Mon Sep 17 00:00:00 2001
From: Daniel Semyonov <daniel@dsemy.com>
Date: Tue, 2 Jul 2024 02:15:24 +0300
Subject: [PATCH] nnatom: Ensure some parsed values are one line

* lisp/gnus/nnatom.el (nnatom--dom-line): New function.
(nnatom--read-title, nnatom--read-description)
(nnatom--read-article-or-group-authors, nnatom--read-subject)
(nnatom--read-id, nnatom--read-publish, nnatom--read-update)
(nnatom--read-links): Read text using `nnatom--dom-line'.
---
 lisp/gnus/nnatom.el | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/lisp/gnus/nnatom.el b/lisp/gnus/nnatom.el
index 13286159784..f6885abb634 100644
--- a/lisp/gnus/nnatom.el
+++ b/lisp/gnus/nnatom.el
@@ -108,15 +108,19 @@ nnatom--read-article
 (defvoo nnatom-read-article-function #'nnatom--read-article
   nil nnfeed-read-article-function)
 
+(defun nnatom--dom-line (node)
+  "Return NODE's text as a single, whitespace-trimmed line."
+  (string-trim (replace-regexp-in-string "[\r\n]+" " " (dom-text node) t)))
+
 (defun nnatom--read-title (group)
   "Return the title of GROUP, or nil."
-  (dom-text (dom-child-by-tag group 'title)))
+  (nnatom--dom-line (dom-child-by-tag group 'title)))
 (defvoo nnatom-read-title-function #'nnatom--read-title
   nil nnfeed-read-title-function)
 
 (defun nnatom--read-description (group)
   "Return the description of GROUP, or nil."
-  (dom-text (dom-child-by-tag group 'subtitle)))
+  (nnatom--dom-line (dom-child-by-tag group 'subtitle)))
 (defvoo nnatom-read-description-function #'nnatom--read-description
   nil nnfeed-read-description-function)
 
@@ -125,9 +129,9 @@ nnatom--read-article-or-group-authors
   (when-let
       ((a (mapconcat
            (lambda (author)
-             (let* ((name (dom-text (dom-child-by-tag author 'name)))
+             (let* ((name (nnatom--dom-line (dom-child-by-tag author 'name)))
                     (name (unless (string-blank-p name) name))
-                    (email (dom-text (dom-child-by-tag author 'email)))
+                    (email (nnatom--dom-line (dom-child-by-tag author 'email)))
                     (email (unless (string-blank-p email) email)))
                (or (and name email (format "%s <%s>" name email)) name email)))
            (dom-children (dom-child-by-tag article-or-group 'authors))
@@ -142,7 +146,7 @@ nnatom-read-group-author-function
 
 (defun nnatom--read-subject (article)
   "Return the subject of ARTICLE, or nil."
-  (dom-text (dom-child-by-tag article 'title)))
+  (nnatom--dom-line (dom-child-by-tag article 'title)))
 (defvoo nnatom-read-subject-function #'nnatom--read-subject
   nil nnfeed-read-subject-function)
 
@@ -150,7 +154,7 @@ nnatom--read-id
   "Return the ID of ARTICLE.
 If the ARTICLE doesn't contain an ID but it does contain a subject,
 return the subject.  Otherwise, return nil."
-  (or (dom-text (dom-child-by-tag article 'id))
+  (or (nnatom--dom-line (dom-child-by-tag article 'id))
       (nnatom--read-subject article)))
 (defvoo nnatom-read-id-function #'nnatom--read-id
   nil nnfeed-read-id-function)
@@ -158,14 +162,14 @@ nnatom-read-id-function
 (defun nnatom--read-publish (article)
   "Return the date and time ARTICLE was published, or nil."
   (when-let (d (dom-child-by-tag article 'published))
-    (date-to-time (dom-text d))))
+    (date-to-time (nnatom--dom-line d))))
 (defvoo nnatom-read-publish-date-function #'nnatom--read-publish
   nil nnfeed-read-publish-date-function)
 
 (defun nnatom--read-update (article)
   "Return the date and time of the last update to ARTICLE, or nil."
   (when-let (d (dom-child-by-tag article 'updated))
-    (date-to-time (dom-text d))))
+    (date-to-time (nnatom--dom-line d))))
 (defvoo nnatom-read-update-date-function #'nnatom--read-update
   nil nnfeed-read-update-date-function)
 
@@ -185,13 +189,13 @@ nnatom--read-links
                (("text/html") . ,(format "<a href=\"%s\">[%s]</a> "
                                          src label)))))
           (when-let (((or (eq l 'author) (eq l 'contributor)))
-                     (name (dom-text (dom-child-by-tag link 'name)))
+                     (name (nnatom--dom-line (dom-child-by-tag link 'name)))
                      (name (if (string-blank-p name)
                                (concat "Author"
                                        (and (< 1 (cl-incf aut))
                                             (format " %s" aut)))
                              name))
-                     (uri (dom-text (dom-child-by-tag link 'uri)))
+                     (uri (nnatom--dom-line (dom-child-by-tag link 'uri)))
                      ((not (string-blank-p uri))))
             `(((("text/plain") . ,(format "%s: %s\n" name uri))
                (("text/html") . ,(format "<a href=\"%s\">[%s]</a> "
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#71889: [PATCH] nnatom: Ensure some parsed values are one line
  2024-07-01 23:44 bug#71889: [PATCH] nnatom: Ensure some parsed values are one line Daniel Semyonov via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-07-02 21:23 ` Daniel Semyonov via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-07-06 10:14   ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Semyonov via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-07-02 21:23 UTC (permalink / raw)
  To: 71889

>>>>> Daniel Semyonov writes:

    > Attached is a patch which ensures some values parsed by nnatom from Atom
    > feeds only contain a single line of whitespace-trimmed text.

Just to clarify, this patch is intended to ensure values parsed from
Atom feeds can be used by Gnus without issues.
Without this patch feeds which contain multiple lines of text in some
nodes can cause strange behavior in Gnus (though I haven't encountered
any actual feeds like this, I had to construct one).

This issue exists in both emacs-30 and the master branch.





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#71889: [PATCH] nnatom: Ensure some parsed values are one line
  2024-07-02 21:23 ` Daniel Semyonov via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-07-06 10:14   ` Eli Zaretskii
  0 siblings, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2024-07-06 10:14 UTC (permalink / raw)
  To: Daniel Semyonov; +Cc: 71889-done

> Date: Wed, 03 Jul 2024 00:23:43 +0300
> From:  Daniel Semyonov via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> 
> >>>>> Daniel Semyonov writes:
> 
>     > Attached is a patch which ensures some values parsed by nnatom from Atom
>     > feeds only contain a single line of whitespace-trimmed text.
> 
> Just to clarify, this patch is intended to ensure values parsed from
> Atom feeds can be used by Gnus without issues.
> Without this patch feeds which contain multiple lines of text in some
> nodes can cause strange behavior in Gnus (though I haven't encountered
> any actual feeds like this, I had to construct one).
> 
> This issue exists in both emacs-30 and the master branch.

Thanks, installed on the emacs-30 branch, and closing the bug.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-07-06 10:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-01 23:44 bug#71889: [PATCH] nnatom: Ensure some parsed values are one line Daniel Semyonov via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-02 21:23 ` Daniel Semyonov via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-06 10:14   ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.