mirror of
https://gitlab.gnome.org/GNOME/libxml2
synced 2025-03-28 21:33:13 +00:00
parser: Don't create reference in xmlLookupGeneralEntity
This should only be done in xmlParseReference. The handling of undeclared entities is still somewhat inconsistent. In element content we create references even if entity substitution is enabled. In attribute values undeclared entities are always ignored.
This commit is contained in:
parent
b717abdd09
commit
45fe9924f0
25
parser.c
25
parser.c
@ -7363,9 +7363,22 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {
|
||||
* We are seeing an entity reference
|
||||
*/
|
||||
name = xmlParseEntityRefInternal(ctxt);
|
||||
if (name != NULL)
|
||||
ent = xmlLookupGeneralEntity(ctxt, name, /* isAttr */ 0);
|
||||
if (ent == NULL) return;
|
||||
if (name == NULL)
|
||||
return;
|
||||
ent = xmlLookupGeneralEntity(ctxt, name, /* isAttr */ 0);
|
||||
if (ent == NULL) {
|
||||
/*
|
||||
* Create a reference for undeclared entities.
|
||||
* TODO: Should we really create a reference if entity
|
||||
* substitution is enabled?
|
||||
*/
|
||||
if ((ctxt->sax != NULL) &&
|
||||
(ctxt->disableSAX == 0) &&
|
||||
(ctxt->sax->reference != NULL)) {
|
||||
ctxt->sax->reference(ctxt->userData, name);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!ctxt->wellFormed)
|
||||
return;
|
||||
|
||||
@ -7602,12 +7615,6 @@ xmlLookupGeneralEntity(xmlParserCtxtPtr ctxt, const xmlChar *name, int inAttr) {
|
||||
} else {
|
||||
xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
|
||||
"Entity '%s' not defined\n", name, NULL);
|
||||
if ((ctxt->inSubset == 0) &&
|
||||
(ctxt->sax != NULL) &&
|
||||
(ctxt->disableSAX == 0) &&
|
||||
(ctxt->sax->reference != NULL)) {
|
||||
ctxt->sax->reference(ctxt->userData, name);
|
||||
}
|
||||
}
|
||||
ctxt->valid = 0;
|
||||
}
|
||||
|
7
result/noent/undeclared-entity.xml
Normal file
7
result/noent/undeclared-entity.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- Having an external DTD makes undeclared entities a warning. -->
|
||||
<!DOCTYPE doc SYSTEM "foo">
|
||||
<doc>
|
||||
<elem attr=""/>
|
||||
<elem>&undeclared;</elem>
|
||||
</doc>
|
24
result/noent/undeclared-entity.xml.sax2
Normal file
24
result/noent/undeclared-entity.xml.sax2
Normal file
@ -0,0 +1,24 @@
|
||||
SAX.setDocumentLocator()
|
||||
SAX.startDocument()
|
||||
SAX.comment( Having an external DTD makes undeclared entities a warning. )
|
||||
SAX.internalSubset(doc, , foo)
|
||||
SAX.externalSubset(doc, , foo)
|
||||
SAX.startElementNs(doc, NULL, NULL, 0, 0, 0)
|
||||
SAX.characters(
|
||||
, 5)
|
||||
SAX.getEntity(undeclared)
|
||||
SAX.warning: Entity 'undeclared' not defined
|
||||
SAX.startElementNs(elem, NULL, NULL, 0, 1, 0, attr='"/>
|
||||
...', 0)
|
||||
SAX.endElementNs(elem, NULL, NULL)
|
||||
SAX.characters(
|
||||
, 5)
|
||||
SAX.startElementNs(elem, NULL, NULL, 0, 0, 0)
|
||||
SAX.getEntity(undeclared)
|
||||
SAX.warning: Entity 'undeclared' not defined
|
||||
SAX.reference(undeclared)
|
||||
SAX.endElementNs(elem, NULL, NULL)
|
||||
SAX.characters(
|
||||
, 1)
|
||||
SAX.endElementNs(doc, NULL, NULL)
|
||||
SAX.endDocument()
|
7
result/undeclared-entity.xml
Normal file
7
result/undeclared-entity.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- Having an external DTD makes undeclared entities a warning. -->
|
||||
<!DOCTYPE doc SYSTEM "foo">
|
||||
<doc>
|
||||
<elem attr=""/>
|
||||
<elem>&undeclared;</elem>
|
||||
</doc>
|
14
result/undeclared-entity.xml.rde
Normal file
14
result/undeclared-entity.xml.rde
Normal file
@ -0,0 +1,14 @@
|
||||
0 8 #comment 0 1 Having an external DTD makes undeclared entities a warning.
|
||||
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
|
||||
|
||||
1 1 elem 0 0
|
||||
2 5 undeclared 0 0
|
||||
1 15 elem 0 0
|
||||
1 14 #text 0 1
|
||||
|
||||
0 15 doc 0 0
|
14
result/undeclared-entity.xml.rdr
Normal file
14
result/undeclared-entity.xml.rdr
Normal file
@ -0,0 +1,14 @@
|
||||
0 8 #comment 0 1 Having an external DTD makes undeclared entities a warning.
|
||||
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
|
||||
|
||||
1 1 elem 0 0
|
||||
2 5 undeclared 0 0
|
||||
1 15 elem 0 0
|
||||
1 14 #text 0 1
|
||||
|
||||
0 15 doc 0 0
|
23
result/undeclared-entity.xml.sax
Normal file
23
result/undeclared-entity.xml.sax
Normal file
@ -0,0 +1,23 @@
|
||||
SAX.setDocumentLocator()
|
||||
SAX.startDocument()
|
||||
SAX.comment( Having an external DTD makes undeclared entities a warning. )
|
||||
SAX.internalSubset(doc, , foo)
|
||||
SAX.externalSubset(doc, , foo)
|
||||
SAX.startElement(doc)
|
||||
SAX.characters(
|
||||
, 5)
|
||||
SAX.getEntity(undeclared)
|
||||
SAX.warning: Entity 'undeclared' not defined
|
||||
SAX.startElement(elem, attr='')
|
||||
SAX.endElement(elem)
|
||||
SAX.characters(
|
||||
, 5)
|
||||
SAX.startElement(elem)
|
||||
SAX.getEntity(undeclared)
|
||||
SAX.warning: Entity 'undeclared' not defined
|
||||
SAX.reference(undeclared)
|
||||
SAX.endElement(elem)
|
||||
SAX.characters(
|
||||
, 1)
|
||||
SAX.endElement(doc)
|
||||
SAX.endDocument()
|
24
result/undeclared-entity.xml.sax2
Normal file
24
result/undeclared-entity.xml.sax2
Normal file
@ -0,0 +1,24 @@
|
||||
SAX.setDocumentLocator()
|
||||
SAX.startDocument()
|
||||
SAX.comment( Having an external DTD makes undeclared entities a warning. )
|
||||
SAX.internalSubset(doc, , foo)
|
||||
SAX.externalSubset(doc, , foo)
|
||||
SAX.startElementNs(doc, NULL, NULL, 0, 0, 0)
|
||||
SAX.characters(
|
||||
, 5)
|
||||
SAX.getEntity(undeclared)
|
||||
SAX.warning: Entity 'undeclared' not defined
|
||||
SAX.startElementNs(elem, NULL, NULL, 0, 1, 0, attr='"/>
|
||||
...', 0)
|
||||
SAX.endElementNs(elem, NULL, NULL)
|
||||
SAX.characters(
|
||||
, 5)
|
||||
SAX.startElementNs(elem, NULL, NULL, 0, 0, 0)
|
||||
SAX.getEntity(undeclared)
|
||||
SAX.warning: Entity 'undeclared' not defined
|
||||
SAX.reference(undeclared)
|
||||
SAX.endElementNs(elem, NULL, NULL)
|
||||
SAX.characters(
|
||||
, 1)
|
||||
SAX.endElementNs(doc, NULL, NULL)
|
||||
SAX.endDocument()
|
6
test/undeclared-entity.xml
Normal file
6
test/undeclared-entity.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<!-- Having an external DTD makes undeclared entities a warning. -->
|
||||
<!DOCTYPE doc SYSTEM "foo">
|
||||
<doc>
|
||||
<elem attr="&undeclared;"/>
|
||||
<elem>&undeclared;</elem>
|
||||
</doc>
|
Loading…
x
Reference in New Issue
Block a user