GNOME Bugzilla – Bug 164142
current namespace isn't popped in empty element
Last modified: 2009-08-15 18:40:50 UTC
Augment sample reader1.c code after node info printf: if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT) { printf(" num attrs:%d", xmlTextReaderAttributeCount(reader)); } Run it with the following case: <test> <child><default xmlns="http://example.com"/></child> <child>shouldn't have a namespace added</child> <child xmlns="">should report empty</child> </test> emptyxmlns.xml:3: warning: Namespace prefix (null) was not found <child>shouldn't have a namespace added</child> ^ 0 1 test 0 0 num attrs:0 1 14 #text 0 1 1 1 child 0 0 num attrs:0 2 1 default 1 0 num attrs:1 1 15 child 0 0 1 14 #text 0 1 1 1 child 0 0 num attrs:1 <--- there shouldn't be an attribute here (it's a NULL namespace) 2 3 #text 0 1 shouldn't have a namespace added 1 15 child 0 0 1 14 #text 0 1 1 1 child 0 0 num attrs:1 2 3 #text 0 1 should report empty 1 15 child 0 0 1 14 #text 0 1 Patch diffed with 2.6.16: (based off of behaviour in xmlParseElement): --- parser.c.orig 2005-01-14 19:30:54.000000000 -0800 +++ parser.c 2005-01-14 19:49:11.000000000 -0800 @@ -9262,6 +9262,8 @@ #endif /* LIBXML_SAX1_ENABLED */ } spacePop(ctxt); + if (nsNr != ctxt->nsNr) + nsPop(ctxt, ctxt->nsNr - nsNr); if (ctxt->nameNr == 0) { ctxt->instate = XML_PARSER_EPILOG; } else {
Created attachment 36045 [details] augmented reader example Reader1 example augmented to display the # of attributes (including namespaces) on an element.
Created attachment 36046 [details] test case
Created attachment 36047 [details] [review] patch for parser.c
Yes this is a real bug, but this was already fixed in CVS since the last release: paphio:~/XML -> cvs -z9 diff -rLIBXML2_2_6_16 parser.c | grep -C5 nsPop @@ -9253,6 +9260,8 @@ (!ctxt->disableSAX)) ctxt->sax->endElementNs(ctxt->userData, name, prefix, URI); + if (ctxt->nsNr - nsNr > 0) + nsPop(ctxt, ctxt->nsNr - nsNr); #ifdef LIBXML_SAX1_ENABLED } else { if ((ctxt->sax != NULL) && @@ -9921,8 +9930,10 @@ return; paphio:~/XML -> thanks anyway ! Daniel
This should be closed by release of libxml2-2.6.17, thanks, Daniel