GNU bug report logs - #34685
26.1; function nnrss-get-namespace-prefix always returns nil

Previous Next

Packages: emacs, gnus;

Reported by: wenbushi <wenbushi <at> gmail.com>

Date: Thu, 28 Feb 2019 15:37:02 UTC

Severity: minor

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 34685 in the body.
You can then email your comments to 34685 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to help-debbugs <at> gnu.org:
bug#34685; Package nnrss. (Thu, 28 Feb 2019 15:37:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to wenbushi <wenbushi <at> gmail.com>:
New bug report received and forwarded. Copy sent to help-debbugs <at> gnu.org. (Thu, 28 Feb 2019 15:37:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: wenbushi <wenbushi <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.1; function nnrss-get-namespace-prefix always returns nil
Date: Thu, 28 Feb 2019 20:31:02 +0800
[Message part 1 (text/plain, inline)]
Package: nnrss

The function "nnrss-get-namespace-prefix" in gnus/nnrss.el always returns
nil,
which causes the contents in "<content:encoded>" tag of an RSS XML not
showing in the gnus article buffer.

Here is a fix:

--- nnrss.el    2019-02-28 20:02:29.224675750 +0800
+++ nnrss-fixed.el      2019-02-28 20:02:04.534267796 +0800
@@ -1031,7 +1031,7 @@
   "Given EL (containing a parsed element) and URI (containing a string
 that gives the URI for which you want to retrieve the namespace
 prefix), return the prefix."
-  (let* ((prefix (car (rassoc uri (cadar el))))
+  (let* ((prefix (car (rassoc uri (cadar (nthcdr 2 (car el))))))
         (nslist (if prefix
                     (split-string (symbol-name prefix) ":")))
         (ns (cond ((eq (length nslist) 1) ; no prefix given


the argument "el" in the function is a list of the parsed XML, like(some
fields are ignored)

((rss ((version . "2.0") (xmlns:atom . "http://www.w3.org/2005/Atom"))
      (channel ((xmlns:content . "http://purl.org/rss/1.0/modules/content/
"))
               (title nil "RSS title")
               (item nil
                     (title nil "article title")
                     (content:encoded nil "article content")))))

The function "nnrss-get-namespace-prefix" should extract tag
"xmlns:content". But it only returns nil because "(cadar el)" matches
nothing.

Hope it helps.
[Message part 2 (text/html, inline)]

bug reassigned from package 'nnrss' to 'emacs,gnus'. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 28 Feb 2019 16:21:04 GMT) Full text and rfc822 format available.

bug No longer marked as found in versions 26.1. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 28 Feb 2019 16:21:04 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org, bugs <at> gnus.org:
bug#34685; Package emacs,gnus. (Fri, 05 Apr 2019 00:52:01 GMT) Full text and rfc822 format available.

Message #12 received at 34685 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: wenbushi <wenbushi <at> gmail.com>
Cc: 34685 <at> debbugs.gnu.org
Subject: Re: bug#34685: 26.1;
 function nnrss-get-namespace-prefix always returns nil
Date: Thu, 04 Apr 2019 20:50:54 -0400
tags 34685 + moreinfo
quit

wenbushi <wenbushi <at> gmail.com> writes:

> The function "nnrss-get-namespace-prefix" in gnus/nnrss.el always
> returns nil, which causes the contents in "<content:encoded>" tag of
> an RSS XML not showing in the gnus article buffer.
>
> Here is a fix:
>
> --- nnrss.el    2019-02-28 20:02:29.224675750 +0800
> +++ nnrss-fixed.el      2019-02-28 20:02:04.534267796 +0800
> @@ -1031,7 +1031,7 @@
>    "Given EL (containing a parsed element) and URI (containing a string
>  that gives the URI for which you want to retrieve the namespace
>  prefix), return the prefix."
> -  (let* ((prefix (car (rassoc uri (cadar el))))
> +  (let* ((prefix (car (rassoc uri (cadar (nthcdr 2 (car el))))))

> the argument "el" in the function is a list of the parsed XML, like(some
> fields are ignored)
>
> ((rss ((version . "2.0") (xmlns:atom . "http://www.w3.org/2005/Atom"))
>       (channel ((xmlns:content . "http://purl.org/rss/1.0/modules/content/"))
>                (title nil "RSS title")
>                (item nil
>                      (title nil "article title")
>                      (content:encoded nil "article content")))))
>
> The function "nnrss-get-namespace-prefix" should extract tag
> "xmlns:content". But it only returns nil because "(cadar el)" matches
> nothing.

That's only due to the particular encoding of your RSS feed though,
isn't it?  I believe xmlns prefixes can technically go on any element in
a document; I expect the current code works for some feeds, and your fix
would break things for them.

We should gather some test cases to be able to fix this properly.




Added tag(s) moreinfo. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 05 Apr 2019 00:52:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org, bugs <at> gnus.org:
bug#34685; Package emacs,gnus. (Fri, 12 Apr 2019 10:22:01 GMT) Full text and rfc822 format available.

Message #17 received at 34685 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: 34685 <at> debbugs.gnu.org
Cc: wenbushi <wenbushi <at> gmail.com>
Subject: Re: bug#34685: 26.1;
 function nnrss-get-namespace-prefix always returns nil
Date: Fri, 12 Apr 2019 06:21:29 -0400
[Message part 1 (text/plain, inline)]
[forwarding to list, please use "Reply All" to keep 34685 <at> debbugs.gnu.org on Cc]

[Message part 2 (message/rfc822, inline)]
From: wenbushi <wenbushi <at> gmail.com>
To: Noam Postavsky <npostavs <at> gmail.com>
Subject: Re: bug#34685: 26.1; function nnrss-get-namespace-prefix always returns nil
Date: Thu, 11 Apr 2019 14:01:23 +0800
[Message part 3 (text/plain, inline)]
Yeah. You're right. Sorry the inconvenience of this mistake.

I've found the tag of my rss feed wasn't in the right place after several
days and forgot to close this issue. After that I didn't check the format
requirements of rss xml carefully though and just made a patch to fix it.
The original codes works well for all other feeds except the outlier I
tested at first(so unlucky!). Maybe it's quite rare for an rss xml to put
its tags in the wrong places.

Thanks for the reply. I should be more careful at testing.

Information forwarded to bug-gnu-emacs <at> gnu.org, bugs <at> gnus.org:
bug#34685; Package emacs,gnus. (Fri, 12 Apr 2019 11:56:02 GMT) Full text and rfc822 format available.

Message #20 received at 34685 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: 34685 <at> debbugs.gnu.org
Cc: wenbushi <wenbushi <at> gmail.com>
Subject: Re: bug#34685: 26.1;
 function nnrss-get-namespace-prefix always returns nil
Date: Fri, 12 Apr 2019 07:55:26 -0400
severity 34685 minor
quit

Noam Postavsky <npostavs <at> gmail.com> writes:

> From: wenbushi <wenbushi <at> gmail.com>

> I've found the tag of my rss feed wasn't in the right place after several
> days and forgot to close this issue. After that I didn't check the format
> requirements of rss xml carefully though and just made a patch to fix it.
> The original codes works well for all other feeds except the outlier I
> tested at first(so unlucky!). Maybe it's quite rare for an rss xml to put
> its tags in the wrong places.

Well, if it's only the one feed, I guess this is not too urgent a bug,
but I don't think the feed is technically wrong.  As I said before, XML
allows xmlns attributes anywhere in the document, so nnrss should be
fixed to handle it.  But we need to have test cases both of the
"outlier" case and "typical" cases to get it right.





Severity set to 'minor' from 'normal' Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 12 Apr 2019 11:56:02 GMT) Full text and rfc822 format available.

Removed tag(s) moreinfo. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Wed, 25 Sep 2019 14:46:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org, bugs <at> gnus.org:
bug#34685; Package emacs,gnus. (Thu, 26 Sep 2019 22:35:01 GMT) Full text and rfc822 format available.

Message #27 received at 34685 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 34685 <at> debbugs.gnu.org, wenbushi <wenbushi <at> gmail.com>
Subject: Re: bug#34685: 26.1; function nnrss-get-namespace-prefix always
 returns nil
Date: Fri, 27 Sep 2019 00:34:15 +0200
Noam Postavsky <npostavs <at> gmail.com> writes:

> Well, if it's only the one feed, I guess this is not too urgent a bug,
> but I don't think the feed is technically wrong.  As I said before, XML
> allows xmlns attributes anywhere in the document, so nnrss should be
> fixed to handle it.  But we need to have test cases both of the
> "outlier" case and "typical" cases to get it right.

I've now fixed this more generally by searching through the DOM for the
URI.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) fixed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Thu, 26 Sep 2019 22:35:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 27.1, send any further explanations to 34685 <at> debbugs.gnu.org and wenbushi <wenbushi <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Thu, 26 Sep 2019 22:35:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 25 Oct 2019 11:24:11 GMT) Full text and rfc822 format available.

bug unarchived. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 09 Aug 2021 12:11:02 GMT) Full text and rfc822 format available.

bug No longer marked as fixed in versions 27.1 and reopened. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 09 Aug 2021 12:11:02 GMT) Full text and rfc822 format available.

Removed tag(s) fixed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 09 Aug 2021 12:11:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org, bugs <at> gnus.org:
bug#34685; Package emacs,gnus. (Mon, 09 Aug 2021 12:14:02 GMT) Full text and rfc822 format available.

Message #42 received at 34685 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Benjamin Riefenstahl <b.riefenstahl <at> turtle-trading.net>
Cc: 34685 <at> debbugs.gnu.org, wenbushi <wenbushi <at> gmail.com>,
 Noam Postavsky <npostavs <at> gmail.com>
Subject: Re: bug#34685: 26.1; function nnrss-get-namespace-prefix always
 returns nil
Date: Mon, 09 Aug 2021 14:13:29 +0200
Benjamin Riefenstahl <b.riefenstahl <at> turtle-trading.net> writes:

> LS09LT0tPQpDb250ZW50LVR5cGU6IHRleHQvcGxhaW4KCkhpIExhcnMsCgpMYXJzIEluZ2Vicmln
> dHNlbiB3cml0ZXM6Cj4gSSd2ZSBub3cgZml4ZWQgdGhpcyBtb3JlIGdlbmVyYWxseSBieSBzZWFy

Your message arrived kinda destroyed, but I used my decoder ring:

> This doesn't seem to work.  I encountered the problem just now on Emacs
> master with https://sql-ledger.com/userforum/index.php?mode=rss .  The
> attached patch fixes it for me.

[...]

> -  (let* ((prefix (car (rassoc uri (dom-attributes
> +  (let* ((prefix (car (or (rassoc uri (dom-attributes el))
> +                          (rassoc uri
> +                                  (dom-attributes

[...]

> +(defconst test-nnrss-xml
> +  '((rss
> +     ((version . "2.0")
> +      (xmlns:dc . "http://purl.org/dc/elements/1.1/"))
> +     (channel
> +      ((xmlns:content . "http://purl.org/rss/1.0/modules/content/"))))))

The problem here is that this test XML isn't a valid DOM -- it's a
list of DOMs.  A valid DOM would be

(defconst test-nnrss-xml
  '(rss
    ((version . "2.0")
     (xmlns:dc . "http://purl.org/dc/elements/1.1/"))
    (channel
     ((xmlns:content . "http://purl.org/rss/1.0/modules/content/")))))

and in this case the test works fine.  So if EL is a list of nodes, then
it's the caller of nnrss-get-namespace-prefix here that should be
adjusted to pass in the car of the list instead?  Could you try that and
see whether that works?  (And send a new patch; I've applied your test
(adjusted).)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org, bugs <at> gnus.org:
bug#34685; Package emacs,gnus. (Mon, 09 Aug 2021 16:31:02 GMT) Full text and rfc822 format available.

Message #45 received at 34685 <at> debbugs.gnu.org (full text, mbox):

From: Benjamin Riefenstahl <b.riefenstahl <at> turtle-trading.net>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 34685 <at> debbugs.gnu.org, wenbushi <wenbushi <at> gmail.com>,
 Noam Postavsky <npostavs <at> gmail.com>
Subject: Re: bug#34685: 26.1; function nnrss-get-namespace-prefix always
 returns nil
Date: Mon, 09 Aug 2021 18:30:01 +0200
[Message part 1 (text/plain, inline)]
Hi Lars,

> Benjamin Riefenstahl <b.riefenstahl <at> turtle-trading.net> writes:
>> LS09LT0tPQpDb250ZW50LVR5cGU6IHRleHQvcGxhaW4KCkhpIExhcnMsCgpMYXJzIEluZ2Vicmln
>> dHNlbiB3cml0ZXM6Cj4gSSd2ZSBub3cgZml4ZWQgdGhpcyBtb3JlIGdlbmVyYWxseSBieSBzZWFy

Lars Ingebrigtsen writes:
> Your message arrived kinda destroyed, but I used my decoder ring:

Sorry about that.  My laptop does not have email setup correctly, that
made things complicated in this case.

>> +(defconst test-nnrss-xml
>> +  '((rss
>> +     ((version . "2.0")
>> +      (xmlns:dc . "http://purl.org/dc/elements/1.1/"))
>> +     (channel
>> +      ((xmlns:content . "http://purl.org/rss/1.0/modules/content/"))))))

> The problem here is that this test XML isn't a valid DOM -- it's a
> list of DOMs.  A valid DOM would be

I originally just copied this from the output of the debugger, so this
is what nnrss-get-namespace-prefix gets passed.  I just checked, the
structure is the result of xml-parse-region, is that supposed to create
something that matches the use of dom-search?  When I try it on some
test XML it does create this same structure again.

Test code:

    (with-temp-buffer
      (insert "<rss xmlns:content='http://purl.org/rss/1.0/modules/content/'>
                 <channel />
               </rss>")
      (xml-parse-region (point-min) (point-max)))

> So if EL is a list of nodes, then it's the caller of
> nnrss-get-namespace-prefix here that should be adjusted to pass in the
> car of the list instead?  Could you try that and see whether that
> works?

What is passed to nnrss-get-namespace-prefix is also used in other
places and the calling function is a bit complicated so I'd rather not
change it.  I attach another change in nnrss-get-namespace-prefix
function instead.

I note that your previous work on this bug is the first time that
nnrss.el uses functions from dom.el.  It maybe should use it more, but
that is a project for another day, I would say.

> (And send a new patch; I've applied your test (adjusted).)

See below.

Thanks for your time,
benny

[0001-Fix-nnrss-get-namespace-prefix-bug-34685.patch (text/x-diff, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org, bugs <at> gnus.org:
bug#34685; Package emacs,gnus. (Tue, 10 Aug 2021 13:49:02 GMT) Full text and rfc822 format available.

Message #48 received at 34685 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Benjamin Riefenstahl <b.riefenstahl <at> turtle-trading.net>
Cc: 34685 <at> debbugs.gnu.org, wenbushi <wenbushi <at> gmail.com>,
 Noam Postavsky <npostavs <at> gmail.com>
Subject: Re: bug#34685: 26.1; function nnrss-get-namespace-prefix always
 returns nil
Date: Tue, 10 Aug 2021 15:48:06 +0200
Benjamin Riefenstahl <b.riefenstahl <at> turtle-trading.net> writes:

> I originally just copied this from the output of the debugger, so this
> is what nnrss-get-namespace-prefix gets passed.  I just checked, the
> structure is the result of xml-parse-region, is that supposed to create
> something that matches the use of dom-search?  When I try it on some
> test XML it does create this same structure again.
>
> Test code:
>
>     (with-temp-buffer
>       (insert "<rss xmlns:content='http://purl.org/rss/1.0/modules/content/'>
>                  <channel />
>                </rss>")
>       (xml-parse-region (point-min) (point-max)))

Ah, I see.  xml-parse-region returns a list of dom objects, while
libxml-parse-xml-region just returns a single object, which is probably
where the confusion here originates from.  (dom.el was written after
libxml2 support was added, and written with the output from that in
mind.)

>> (And send a new patch; I've applied your test (adjusted).)
>
> See below.

Thanks; applied to Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug marked as fixed in version 28.1, send any further explanations to 34685 <at> debbugs.gnu.org and wenbushi <wenbushi <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 10 Aug 2021 13:49:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 08 Sep 2021 11:24:09 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 224 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.