From 7d446e9736f69e42fdf96e8b5507ed282ccc1c25 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Fri, 8 Dec 2023 12:13:49 +0100 Subject: [PATCH] parser: Fix namespaces redefined from default attributes This regressed in commit e0dd330b. Also fixes a long-standing issue where namespaces from default attributes weren't added if they match an existing namespace. Fixes #643. --- parser.c | 12 ++++-------- result/issue643.xml | 8 ++++++++ result/issue643.xml.rde | 8 ++++++++ result/issue643.xml.rdr | 8 ++++++++ result/issue643.xml.sax | 15 +++++++++++++++ result/issue643.xml.sax2 | 15 +++++++++++++++ result/noent/issue643.xml | 8 ++++++++ result/noent/issue643.xml.sax2 | 15 +++++++++++++++ result/valid/ns2.xml | 2 +- test/issue643.xml | 9 +++++++++ 10 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 result/issue643.xml create mode 100644 result/issue643.xml.rde create mode 100644 result/issue643.xml.rdr create mode 100644 result/issue643.xml.sax create mode 100644 result/issue643.xml.sax2 create mode 100644 result/noent/issue643.xml create mode 100644 result/noent/issue643.xml.sax2 create mode 100644 test/issue643.xml diff --git a/parser.c b/parser.c index ab49caba..699fccd9 100644 --- a/parser.c +++ b/parser.c @@ -1689,13 +1689,11 @@ xmlParserNsPush(xmlParserCtxtPtr ctxt, const xmlHashedString *prefix, oldIndex = ctxt->nsdb->defaultNsIndex; if (oldIndex != INT_MAX) { - if (defAttr != 0) - return(0); - extra = &ctxt->nsdb->extra[oldIndex]; if (extra->elementId == ctxt->nsdb->elementId) { - xmlErrAttributeDup(ctxt, NULL, BAD_CAST "xmlns"); + if (defAttr == 0) + xmlErrAttributeDup(ctxt, NULL, BAD_CAST "xmlns"); return(0); } @@ -1715,14 +1713,12 @@ xmlParserNsPush(xmlParserCtxtPtr ctxt, const xmlHashedString *prefix, if (oldIndex != INT_MAX) { extra = &ctxt->nsdb->extra[oldIndex]; - if (defAttr != 0) - return(0); - /* * Check for duplicate definitions on the same element. */ if (extra->elementId == ctxt->nsdb->elementId) { - xmlErrAttributeDup(ctxt, BAD_CAST "xmlns", prefix->name); + if (defAttr == 0) + xmlErrAttributeDup(ctxt, BAD_CAST "xmlns", prefix->name); return(0); } diff --git a/result/issue643.xml b/result/issue643.xml new file mode 100644 index 00000000..3a5a92cc --- /dev/null +++ b/result/issue643.xml @@ -0,0 +1,8 @@ + + + +]> + + + diff --git a/result/issue643.xml.rde b/result/issue643.xml.rde new file mode 100644 index 00000000..b8ca1392 --- /dev/null +++ b/result/issue643.xml.rde @@ -0,0 +1,8 @@ +0 10 doc 0 0 +0 1 doc 0 0 +1 14 #text 0 1 + +1 1 elem 1 0 +1 14 #text 0 1 + +0 15 doc 0 0 diff --git a/result/issue643.xml.rdr b/result/issue643.xml.rdr new file mode 100644 index 00000000..b8ca1392 --- /dev/null +++ b/result/issue643.xml.rdr @@ -0,0 +1,8 @@ +0 10 doc 0 0 +0 1 doc 0 0 +1 14 #text 0 1 + +1 1 elem 1 0 +1 14 #text 0 1 + +0 15 doc 0 0 diff --git a/result/issue643.xml.sax b/result/issue643.xml.sax new file mode 100644 index 00000000..85563b96 --- /dev/null +++ b/result/issue643.xml.sax @@ -0,0 +1,15 @@ +SAX.setDocumentLocator() +SAX.startDocument() +SAX.internalSubset(doc, , ) +SAX.attributeDecl(elem, xmlns, 1, 4, urn:def2, ...) +SAX.attributeDecl(elem, xmlns:a, 1, 4, urn:a2, ...) +SAX.externalSubset(doc, , ) +SAX.startElement(doc, xmlns='urn:def', xmlns:a='urn:a') +SAX.characters( + , 5) +SAX.startElement(elem) +SAX.endElement(elem) +SAX.characters( +, 1) +SAX.endElement(doc) +SAX.endDocument() diff --git a/result/issue643.xml.sax2 b/result/issue643.xml.sax2 new file mode 100644 index 00000000..cd7e5f1c --- /dev/null +++ b/result/issue643.xml.sax2 @@ -0,0 +1,15 @@ +SAX.setDocumentLocator() +SAX.startDocument() +SAX.internalSubset(doc, , ) +SAX.attributeDecl(elem, xmlns, 1, 4, urn:def2, ...) +SAX.attributeDecl(elem, xmlns:a, 1, 4, urn:a2, ...) +SAX.externalSubset(doc, , ) +SAX.startElementNs(doc, NULL, 'urn:def', 2, xmlns='urn:def', xmlns:a='urn:a', 0, 0) +SAX.characters( + , 5) +SAX.startElementNs(elem, NULL, 'urn:def2', 2, xmlns='urn:def2', xmlns:a='urn:a2', 0, 0) +SAX.endElementNs(elem, NULL, 'urn:def2') +SAX.characters( +, 1) +SAX.endElementNs(doc, NULL, 'urn:def') +SAX.endDocument() diff --git a/result/noent/issue643.xml b/result/noent/issue643.xml new file mode 100644 index 00000000..3a5a92cc --- /dev/null +++ b/result/noent/issue643.xml @@ -0,0 +1,8 @@ + + + +]> + + + diff --git a/result/noent/issue643.xml.sax2 b/result/noent/issue643.xml.sax2 new file mode 100644 index 00000000..cd7e5f1c --- /dev/null +++ b/result/noent/issue643.xml.sax2 @@ -0,0 +1,15 @@ +SAX.setDocumentLocator() +SAX.startDocument() +SAX.internalSubset(doc, , ) +SAX.attributeDecl(elem, xmlns, 1, 4, urn:def2, ...) +SAX.attributeDecl(elem, xmlns:a, 1, 4, urn:a2, ...) +SAX.externalSubset(doc, , ) +SAX.startElementNs(doc, NULL, 'urn:def', 2, xmlns='urn:def', xmlns:a='urn:a', 0, 0) +SAX.characters( + , 5) +SAX.startElementNs(elem, NULL, 'urn:def2', 2, xmlns='urn:def2', xmlns:a='urn:a2', 0, 0) +SAX.endElementNs(elem, NULL, 'urn:def2') +SAX.characters( +, 1) +SAX.endElementNs(doc, NULL, 'urn:def') +SAX.endDocument() diff --git a/result/valid/ns2.xml b/result/valid/ns2.xml index a4c30a85..beacf15d 100644 --- a/result/valid/ns2.xml +++ b/result/valid/ns2.xml @@ -7,5 +7,5 @@ ]> - + diff --git a/test/issue643.xml b/test/issue643.xml new file mode 100644 index 00000000..e4efeaa5 --- /dev/null +++ b/test/issue643.xml @@ -0,0 +1,9 @@ + + + +]> + + + +