mirror of
https://github.com/GNOME/libxml2.git
synced 2025-03-19 18:50:25 +08:00
humm, changed the way the SAX parser work when
* parser.c: humm, changed the way the SAX parser work when xmlSubstituteEntitiesDefault(1) is set, it will then do the entity registration and loading by itself in case the user provided SAX getEntity() returns NULL. * testSAX.c: added --noent to test the behaviour. Daniel
This commit is contained in:
parent
b5a60eccfd
commit
5997aca8b8
@ -1,3 +1,11 @@
|
||||
Mon Mar 18 19:18:13 CET 2002 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* parser.c: humm, changed the way the SAX parser work when
|
||||
xmlSubstituteEntitiesDefault(1) is set, it will then
|
||||
do the entity registration and loading by itself in case the
|
||||
user provided SAX getEntity() returns NULL.
|
||||
* testSAX.c: added --noent to test the behaviour.
|
||||
|
||||
Mon Mar 18 12:44:23 CET 2002 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* parser.c: Wilfried Teiken provided a hackish but working
|
||||
|
53
parser.c
53
parser.c
@ -79,6 +79,8 @@
|
||||
#define XML_PARSER_BIG_BUFFER_SIZE 300
|
||||
#define XML_PARSER_BUFFER_SIZE 100
|
||||
|
||||
#define SAX_COMPAT_MODE BAD_CAST "SAX compatibility mode document"
|
||||
|
||||
/*
|
||||
* List of XML prefixed PI allowed by W3C specs
|
||||
*/
|
||||
@ -3459,6 +3461,21 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
|
||||
ctxt->sax->entityDecl(ctxt->userData, name,
|
||||
XML_INTERNAL_GENERAL_ENTITY,
|
||||
NULL, NULL, value);
|
||||
/*
|
||||
* For expat compatibility in SAX mode.
|
||||
*/
|
||||
if ((ctxt->myDoc == NULL) ||
|
||||
(xmlStrEqual(ctxt->myDoc->version, SAX_COMPAT_MODE))) {
|
||||
if (ctxt->myDoc == NULL) {
|
||||
ctxt->myDoc = xmlNewDoc(SAX_COMPAT_MODE);
|
||||
}
|
||||
if (ctxt->myDoc->intSubset == NULL)
|
||||
ctxt->myDoc->intSubset = xmlNewDtd(ctxt->myDoc,
|
||||
BAD_CAST "fake", NULL, NULL);
|
||||
|
||||
entityDecl(ctxt, name, XML_INTERNAL_GENERAL_ENTITY,
|
||||
NULL, NULL, value);
|
||||
}
|
||||
} else {
|
||||
URI = xmlParseExternalID(ctxt, &literal, 1);
|
||||
if ((URI == NULL) && (literal == NULL)) {
|
||||
@ -3535,6 +3552,24 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
|
||||
ctxt->sax->entityDecl(ctxt->userData, name,
|
||||
XML_EXTERNAL_GENERAL_PARSED_ENTITY,
|
||||
literal, URI, NULL);
|
||||
/*
|
||||
* For expat compatibility in SAX mode.
|
||||
* assuming the entity repalcement was asked for
|
||||
*/
|
||||
if ((ctxt->replaceEntities != 0) &&
|
||||
((ctxt->myDoc == NULL) ||
|
||||
(xmlStrEqual(ctxt->myDoc->version, SAX_COMPAT_MODE)))) {
|
||||
if (ctxt->myDoc == NULL) {
|
||||
ctxt->myDoc = xmlNewDoc(SAX_COMPAT_MODE);
|
||||
}
|
||||
|
||||
if (ctxt->myDoc->intSubset == NULL)
|
||||
ctxt->myDoc->intSubset = xmlNewDtd(ctxt->myDoc,
|
||||
BAD_CAST "fake", NULL, NULL);
|
||||
entityDecl(ctxt, name,
|
||||
XML_EXTERNAL_GENERAL_PARSED_ENTITY,
|
||||
literal, URI, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3571,6 +3606,9 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
|
||||
if ((ctxt->sax != NULL) &&
|
||||
(ctxt->sax->getEntity != NULL))
|
||||
cur = ctxt->sax->getEntity(ctxt->userData, name);
|
||||
if ((cur == NULL) && (ctxt->userData==ctxt)) {
|
||||
cur = getEntity(ctxt, name);
|
||||
}
|
||||
}
|
||||
if (cur != NULL) {
|
||||
if (cur->orig != NULL)
|
||||
@ -5492,6 +5530,9 @@ xmlParseEntityRef(xmlParserCtxtPtr ctxt) {
|
||||
ent = ctxt->sax->getEntity(ctxt->userData, name);
|
||||
if (ent == NULL)
|
||||
ent = xmlGetPredefinedEntity(name);
|
||||
if ((ent == NULL) && (ctxt->userData==ctxt)) {
|
||||
ent = getEntity(ctxt, name);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* [ WFC: Entity Declared ]
|
||||
@ -5686,6 +5727,9 @@ xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const xmlChar ** str) {
|
||||
ent = ctxt->sax->getEntity(ctxt->userData, name);
|
||||
if (ent == NULL)
|
||||
ent = xmlGetPredefinedEntity(name);
|
||||
if ((ent == NULL) && (ctxt->userData==ctxt)) {
|
||||
ent = getEntity(ctxt, name);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* [ WFC: Entity Declared ]
|
||||
@ -7655,6 +7699,15 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {
|
||||
if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
|
||||
ctxt->sax->endDocument(ctxt->userData);
|
||||
|
||||
/*
|
||||
* Remove locally kept entity definitions if the tree was not built
|
||||
*/
|
||||
if ((ctxt->myDoc != NULL) &&
|
||||
(xmlStrEqual(ctxt->myDoc->version, SAX_COMPAT_MODE))) {
|
||||
xmlFreeDoc(ctxt->myDoc);
|
||||
ctxt->myDoc = NULL;
|
||||
}
|
||||
|
||||
if (! ctxt->wellFormed) {
|
||||
ctxt->valid = 0;
|
||||
return(-1);
|
||||
|
@ -57,11 +57,11 @@ $(GENERATED): $(srcdir)/$(GENERATE) $(API_DESC)
|
||||
cd $(srcdir) && $(PYTHON) $(GENERATE)
|
||||
|
||||
$(libxml2mod_la_OBJECTS): $(GENERATED)
|
||||
|
||||
else
|
||||
all:
|
||||
endif
|
||||
|
||||
tests: all
|
||||
tests test: all
|
||||
cd tests && $(MAKE) tests
|
||||
|
||||
clean:
|
||||
|
@ -44,6 +44,7 @@ static int copy = 0;
|
||||
static int recovery = 0;
|
||||
static int push = 0;
|
||||
static int speed = 0;
|
||||
static int noent = 0;
|
||||
|
||||
xmlSAXHandler emptySAXHandlerStruct = {
|
||||
NULL, /* internalSubset */
|
||||
@ -718,7 +719,11 @@ int main(int argc, char **argv) {
|
||||
else if ((!strcmp(argv[i], "-speed")) ||
|
||||
(!strcmp(argv[i], "--speed")))
|
||||
speed++;
|
||||
else if ((!strcmp(argv[i], "-noent")) ||
|
||||
(!strcmp(argv[i], "--noent")))
|
||||
noent++;
|
||||
}
|
||||
if (noent != 0) xmlSubstituteEntitiesDefault(1);
|
||||
for (i = 1; i < argc ; i++) {
|
||||
if (argv[i][0] != '-') {
|
||||
parseAndPrintFile(argv[i]);
|
||||
|
2
tree.c
2
tree.c
@ -556,6 +556,8 @@ xmlFreeDoc(xmlDocPtr cur) {
|
||||
cur->refs = NULL;
|
||||
extSubset = cur->extSubset;
|
||||
intSubset = cur->intSubset;
|
||||
if (intSubset == extSubset)
|
||||
extSubset = NULL;
|
||||
if (extSubset != NULL) {
|
||||
xmlUnlinkNode((xmlNodePtr) cur->extSubset);
|
||||
cur->extSubset = NULL;
|
||||
|
@ -653,6 +653,8 @@ xmlMemoryDump(void)
|
||||
{
|
||||
FILE *dump;
|
||||
|
||||
if (debugMaxMemSize == 0)
|
||||
return;
|
||||
dump = fopen(".memdump", "w");
|
||||
if (dump == NULL)
|
||||
xmlMemoryDumpFile = stderr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user