GNU bug report logs - #27178
libxml-parse-*-region functions discard-comments argument only applies to top level comments

Previous Next

Package: emacs;

Reported by: Sean McAfee <eefacm <at> gmail.com>

Date: Thu, 1 Jun 2017 00:08:02 UTC

Severity: normal

Tags: confirmed, fixed

Found in versions 26.0.50, 25.2

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

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: npostavs <at> users.sourceforge.net
Cc: 27178 <at> debbugs.gnu.org, Sean McAfee <eefacm <at> gmail.com>
Subject: bug#27178: 26.0.50; libxml-parse-*-region functions ignore discard-comments argument
Date: Sat, 14 Apr 2018 00:54:09 +0200
I tried the following, but it's not correct, since it resulted in

(html nil (body nil (p nil "This " nil " that")))

But what should the result be here?

(html nil (body nil (p nil "This that")))

or

(html nil (body nil (p nil "This " " that")))

?

I think the former...  Which means that you'd have to do some major
doctoring of the structures, I think?

diff --git a/src/xml.c b/src/xml.c
index 42059d7713..bf416407da 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -119,7 +119,7 @@ init_libxml2_functions (void)
 }
 
 static Lisp_Object
-make_dom (xmlNode *node)
+make_dom (xmlNode *node, bool discard_comments)
 {
   if (node->type == XML_ELEMENT_NODE)
     {
@@ -148,7 +148,7 @@ make_dom (xmlNode *node)
       child = node->children;
       while (child != NULL)
 	{
-	  result = Fcons (make_dom (child), result);
+	  result = Fcons (make_dom (child, discard_comments), result);
 	  child = child->next;
 	}
 
@@ -163,7 +163,7 @@ make_dom (xmlNode *node)
     }
   else if (node->type == XML_COMMENT_NODE)
     {
-      if (node->content)
+      if (node->content && ! discard_comments)
 	return list3 (intern ("comment"), Qnil,
 		      build_string ((char *) node->content));
       else
@@ -239,7 +239,7 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url,
           while (n) {
             if (!NILP (r))
               result = Fcons (r, result);
-            r = make_dom (n);
+            r = make_dom (n, false);
             n = n->next;
           }
         }
@@ -249,7 +249,7 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url,
 	   them.  Get the tree the proper way. */
 	xmlNode *node = xmlDocGetRootElement (doc);
 	if (node != NULL)
-	  result = make_dom (node);
+	  result = make_dom (node, !NILP(discard_comments));
       } else
 	result = Fcons (Qtop, Fcons (Qnil, Fnreverse (Fcons (r, result))));
 


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





This bug report was last modified 7 years and 118 days ago.

Previous Next


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