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.
This commit is contained in:
Nick Wellnhofer 2023-12-08 12:13:49 +01:00
parent df0b540b3e
commit 7d446e9736
10 changed files with 91 additions and 9 deletions

View File

@ -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);
}

8
result/issue643.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!DOCTYPE doc [
<!ATTLIST elem xmlns CDATA #FIXED "urn:def2">
<!ATTLIST elem xmlns:a CDATA #FIXED "urn:a2">
]>
<doc xmlns="urn:def" xmlns:a="urn:a">
<elem xmlns="urn:def2" xmlns:a="urn:a2"/>
</doc>

8
result/issue643.xml.rde Normal file
View File

@ -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

8
result/issue643.xml.rdr Normal file
View File

@ -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

15
result/issue643.xml.sax Normal file
View File

@ -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()

15
result/issue643.xml.sax2 Normal file
View File

@ -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()

View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!DOCTYPE doc [
<!ATTLIST elem xmlns CDATA #FIXED "urn:def2">
<!ATTLIST elem xmlns:a CDATA #FIXED "urn:a2">
]>
<doc xmlns="urn:def" xmlns:a="urn:a">
<elem xmlns="urn:def2" xmlns:a="urn:a2"/>
</doc>

View File

@ -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()

View File

@ -7,5 +7,5 @@
<!ATTLIST a:inner attr CDATA #FIXED "yes">
]>
<a:outer xmlns:a="urn:namespace">
<a:inner/>
<a:inner xmlns:a="urn:namespace"/>
</a:outer>

9
test/issue643.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<!DOCTYPE doc [
<!ATTLIST elem xmlns CDATA #FIXED 'urn:def2'>
<!ATTLIST elem xmlns:a CDATA #FIXED 'urn:a2'>
]>
<doc xmlns="urn:def" xmlns:a="urn:a">
<elem/>
</doc>