1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00

parser: Synchronize more options

This commit is contained in:
Nick Wellnhofer 2024-01-05 01:14:28 +01:00
parent 3efbe916a1
commit 12f0bb9478
7 changed files with 62 additions and 77 deletions

View File

@ -295,7 +295,7 @@ static int xmlDoValidityCheckingDefaultValueThrDef = 0;
/**
* xmlGetWarningsDefaultValue:
*
* DEPRECATED: Don't use
* DEPRECATED: Use the modern options API with XML_PARSE_NOWARNING.
*
* Global setting, indicate that the DTD validation should provide warnings.
* Activated by default.

View File

@ -39,18 +39,7 @@ extern "C" {
* a) default attributes (if any) are added to all nodes
* b) all character and parsed entity references are resolved
* In order to achieve this in libxml2 the document MUST be loaded with
* following global settings:
*
* xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
* xmlSubstituteEntitiesDefault(1);
*
* or corresponding parser context setting:
* xmlParserCtxtPtr ctxt;
*
* ...
* ctxt->loadsubset = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
* ctxt->replaceEntities = 1;
* ...
* following options: XML_PARSE_DTDATTR | XML_PARSE_NOENT
*/
/*

View File

@ -132,30 +132,14 @@ typedef enum {
XML_PARSER_XML_DECL /* before XML decl (but after BOM) */
} xmlParserInputState;
/**
* XML_DETECT_IDS:
*
* Bit in the loadsubset context field to tell to do ID/REFs lookups.
* Use it to initialize xmlLoadExtDtdDefaultValue.
/** DOC_DISABLE */
/*
* Internal bits in the 'loadsubset' context member
*/
#define XML_DETECT_IDS 2
/**
* XML_COMPLETE_ATTRS:
*
* Bit in the loadsubset context field to tell to do complete the
* elements attributes lists with the ones defaulted from the DTDs.
* Use it to initialize xmlLoadExtDtdDefaultValue.
*/
#define XML_COMPLETE_ATTRS 4
/**
* XML_SKIP_IDS:
*
* Bit in the loadsubset context field to tell to not do ID/REFs registration.
* Used to initialize xmlLoadExtDtdDefaultValue in some special cases.
*/
#define XML_SKIP_IDS 8
/** DOC_ENABLE */
/**
* xmlParserMode:

View File

@ -3796,9 +3796,8 @@ xmlExpandPEsInEntityValue(xmlParserCtxtPtr ctxt, xmlSBuf *buf,
* complete external PEReferences coming from the
* internal subset
*/
if (((ctxt->options & XML_PARSE_NOENT) != 0) ||
((ctxt->options & XML_PARSE_DTDVALID) != 0) ||
(ctxt->validate != 0)) {
if ((ctxt->replaceEntities) ||
(ctxt->validate)) {
xmlLoadEntityContent(ctxt, ent);
} else {
xmlWarningMsg(ctxt, XML_ERR_ENTITY_PROCESSING,
@ -10612,8 +10611,8 @@ xmlParseExtParsedEnt(xmlParserCtxtPtr ctxt) {
/*
* Doing validity checking on chunk doesn't make sense
*/
ctxt->options &= ~XML_PARSE_DTDVALID;
ctxt->validate = 0;
ctxt->loadsubset = 0;
ctxt->depth = 0;
xmlParseContentInternal(ctxt);
@ -11595,6 +11594,7 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
if (ctxt == NULL)
return(NULL);
ctxt->options &= ~XML_PARSE_NODICT;
ctxt->dictNames = 1;
input = xmlNewInputPush(ctxt, filename, chunk, size, NULL);
@ -11698,9 +11698,6 @@ xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBufferPtr input,
return(NULL);
}
/* We are loading a DTD */
ctxt->options |= XML_PARSE_DTDLOAD;
/*
* generate a parser input from the I/O handler
*/
@ -11790,9 +11787,6 @@ xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *ExternalID,
return(NULL);
}
/* We are loading a DTD */
ctxt->options |= XML_PARSE_DTDLOAD;
/*
* Canonicalise the system ID
*/
@ -12292,8 +12286,10 @@ xmlParseInNodeContext(xmlNodePtr node, const char *data, int datalen,
if (ctxt->dict != NULL)
xmlDictFree(ctxt->dict);
ctxt->dict = doc->dict;
} else
} else {
options |= XML_PARSE_NODICT;
ctxt->dictNames = 0;
}
if (doc->encoding != NULL)
xmlSwitchEncodingName(ctxt, (const char *) doc->encoding);
@ -12446,8 +12442,10 @@ xmlParseBalancedChunkMemoryRecover(xmlDocPtr doc, xmlSAXHandlerPtr sax,
ctxt->depth = depth;
ctxt->myDoc = doc;
if (recover)
if (recover) {
ctxt->options |= XML_PARSE_RECOVER;
ctxt->recovery = 1;
}
input = xmlNewStringInputStream(ctxt, string);
if (input == NULL)
@ -12680,7 +12678,10 @@ xmlSAXParseFileWithData(xmlSAXHandlerPtr sax, const char *filename,
if (data != NULL)
ctxt->_private = data;
ctxt->recovery = recovery;
if (recovery) {
ctxt->options |= XML_PARSE_RECOVER;
ctxt->recovery = 1;
}
input = xmlNewInputURL(ctxt, filename, NULL, NULL, 0);
@ -12926,7 +12927,10 @@ xmlSAXParseMemoryWithData(xmlSAXHandlerPtr sax, const char *buffer,
if (data != NULL)
ctxt->_private=data;
ctxt->recovery = recovery;
if (recovery) {
ctxt->options |= XML_PARSE_RECOVER;
ctxt->recovery = 1;
}
input = xmlNewInputMemory(ctxt, NULL, buffer, size, NULL,
XML_INPUT_BUF_STATIC);
@ -13332,6 +13336,9 @@ xmlCtxtSetOptionsInternal(xmlParserCtxtPtr ctxt, int options, int keepMask)
* Once public access to struct members and the globals are
* disabled, we can use the options bitmask as source of
* truth, making all these struct members obsolete.
*
* The XML_DETECT_IDS flags is misnamed. It simply enables
* loading of the external subset.
*/
ctxt->recovery = (options & XML_PARSE_RECOVER) ? 1 : 0;
ctxt->replaceEntities = (options & XML_PARSE_NOENT) ? 1 : 0;
@ -13382,14 +13389,11 @@ xmlCtxtSetOptionsInternal(xmlParserCtxtPtr ctxt, int options, int keepMask)
*
* Despite the confusing name, this option enables substitution
* of entities. The resulting tree won't contain any entity
* reference nodes. This option also enables loading of
* external entities which is dangerous. If you process
* untrusted data, it's recommended to set up an external entity
* loader that validates the files or URIs being loaded.
*
* This option also enables the loading and substitution of
* external parameter entities. Internal parameter entities are
* always expanded.
* reference nodes. This option also enables loading of external
* entities (both general and parameter entities) which is
* dangerous. If you process untrusted data, it's recommended to
* set up an external entity loader that validates the files or
* URIs being loaded.
*
* XML_PARSE_DTDLOAD
*
@ -13404,9 +13408,9 @@ xmlCtxtSetOptionsInternal(xmlParserCtxtPtr ctxt, int options, int keepMask)
*
* XML_PARSE_DTDVALID
*
* This option enables DTD validation.
*
* Implies XML_PARSE_DTDLOAD.
* This option enables DTD validation which requires to load
* external DTDs and external entities (both general and
* parameter entities).
*
* XML_PARSE_NOERROR
*

View File

@ -2297,11 +2297,23 @@ xmlInitSAXParserCtxt(xmlParserCtxtPtr ctxt, const xmlSAXHandler *sax,
ctxt->wellFormed = 1;
ctxt->nsWellFormed = 1;
ctxt->valid = 1;
ctxt->options = XML_PARSE_NODICT;
/*
* Initialize some parser options from deprecated global variables.
* Note that the "modern" API taking options arguments or
* xmlCtxtSetOptions will ignore these defaults. They're only
* relevant if old API functions like xmlParseFile are used.
*/
ctxt->loadsubset = xmlLoadExtDtdDefaultValue;
if (ctxt->loadsubset) {
ctxt->options |= XML_PARSE_DTDLOAD;
}
ctxt->validate = xmlDoValidityCheckingDefaultValue;
if (ctxt->validate) {
ctxt->options |= XML_PARSE_DTDVALID;
}
ctxt->pedantic = xmlPedanticParserDefaultValue;
if (ctxt->pedantic) {
ctxt->options |= XML_PARSE_PEDANTIC;
@ -2312,23 +2324,18 @@ xmlInitSAXParserCtxt(xmlParserCtxtPtr ctxt, const xmlSAXHandler *sax,
ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
ctxt->options |= XML_PARSE_NOBLANKS;
}
ctxt->replaceEntities = xmlSubstituteEntitiesDefaultValue;
if (ctxt->replaceEntities) {
ctxt->options |= XML_PARSE_NOENT;
}
if (xmlGetWarningsDefaultValue == 0)
ctxt->options |= XML_PARSE_NOWARNING;
ctxt->vctxt.flags = XML_VCTXT_USE_PCTXT;
ctxt->vctxt.userData = ctxt;
ctxt->vctxt.error = xmlParserValidityError;
ctxt->vctxt.warning = xmlParserValidityWarning;
if (ctxt->validate) {
if (xmlGetWarningsDefaultValue == 0)
ctxt->vctxt.warning = NULL;
else
ctxt->vctxt.warning = xmlParserValidityWarning;
ctxt->vctxt.nodeMax = 0;
ctxt->options |= XML_PARSE_DTDVALID;
}
ctxt->replaceEntities = xmlSubstituteEntitiesDefaultValue;
if (ctxt->replaceEntities) {
ctxt->options |= XML_PARSE_NOENT;
}
ctxt->record_info = 0;
ctxt->checkIndex = 0;
ctxt->inSubset = 0;

View File

@ -330,7 +330,7 @@ xmlXIncludeParseFile(xmlXIncludeCtxtPtr ctxt, const char *URL) {
xmlDictReference(pctxt->dict);
}
xmlCtxtUseOptions(pctxt, ctxt->parseFlags | XML_PARSE_DTDLOAD);
xmlCtxtUseOptions(pctxt, ctxt->parseFlags);
inputStream = xmlLoadExternalEntity(URL, NULL, pctxt);
if (inputStream == NULL)
@ -338,8 +338,6 @@ xmlXIncludeParseFile(xmlXIncludeCtxtPtr ctxt, const char *URL) {
inputPush(pctxt, inputStream);
pctxt->loadsubset |= XML_DETECT_IDS;
xmlParseDocument(pctxt);
if (pctxt->wellFormed) {

View File

@ -3718,18 +3718,21 @@ xmlTextReaderSetParserProp(xmlTextReaderPtr reader, int prop, int value) {
if (ctxt->loadsubset == 0) {
if (reader->mode != XML_TEXTREADER_MODE_INITIAL)
return(-1);
ctxt->loadsubset = XML_DETECT_IDS;
ctxt->options |= XML_PARSE_DTDLOAD;
ctxt->loadsubset |= XML_DETECT_IDS;
}
} else {
ctxt->loadsubset = 0;
ctxt->options &= ~XML_PARSE_DTDLOAD;
ctxt->loadsubset &= ~XML_DETECT_IDS;
}
return(0);
case XML_PARSER_DEFAULTATTRS:
if (value != 0) {
ctxt->options |= XML_PARSE_DTDATTR;
ctxt->loadsubset |= XML_COMPLETE_ATTRS;
} else {
if (ctxt->loadsubset & XML_COMPLETE_ATTRS)
ctxt->loadsubset -= XML_COMPLETE_ATTRS;
ctxt->options &= ~XML_PARSE_DTDATTR;
ctxt->loadsubset &= ~XML_COMPLETE_ATTRS;
}
return(0);
case XML_PARSER_VALIDATE: