mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-01-15 23:24:06 +03:00
Improve error reporting on parser errors
The extra string was being dismissed when provided. * parser.c: handle bot case properly * result/: this changes a few error reports
This commit is contained in:
parent
48b4cdde34
commit
e7bf892d8c
121
parser.c
121
parser.c
@ -289,196 +289,201 @@ static void
|
||||
xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info)
|
||||
{
|
||||
const char *errmsg;
|
||||
char errstr[129] = "";
|
||||
|
||||
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
|
||||
(ctxt->instate == XML_PARSER_EOF))
|
||||
return;
|
||||
switch (error) {
|
||||
case XML_ERR_INVALID_HEX_CHARREF:
|
||||
errmsg = "CharRef: invalid hexadecimal value\n";
|
||||
errmsg = "CharRef: invalid hexadecimal value";
|
||||
break;
|
||||
case XML_ERR_INVALID_DEC_CHARREF:
|
||||
errmsg = "CharRef: invalid decimal value\n";
|
||||
errmsg = "CharRef: invalid decimal value";
|
||||
break;
|
||||
case XML_ERR_INVALID_CHARREF:
|
||||
errmsg = "CharRef: invalid value\n";
|
||||
errmsg = "CharRef: invalid value";
|
||||
break;
|
||||
case XML_ERR_INTERNAL_ERROR:
|
||||
errmsg = "internal error";
|
||||
break;
|
||||
case XML_ERR_PEREF_AT_EOF:
|
||||
errmsg = "PEReference at end of document\n";
|
||||
errmsg = "PEReference at end of document";
|
||||
break;
|
||||
case XML_ERR_PEREF_IN_PROLOG:
|
||||
errmsg = "PEReference in prolog\n";
|
||||
errmsg = "PEReference in prolog";
|
||||
break;
|
||||
case XML_ERR_PEREF_IN_EPILOG:
|
||||
errmsg = "PEReference in epilog\n";
|
||||
errmsg = "PEReference in epilog";
|
||||
break;
|
||||
case XML_ERR_PEREF_NO_NAME:
|
||||
errmsg = "PEReference: no name\n";
|
||||
errmsg = "PEReference: no name";
|
||||
break;
|
||||
case XML_ERR_PEREF_SEMICOL_MISSING:
|
||||
errmsg = "PEReference: expecting ';'\n";
|
||||
errmsg = "PEReference: expecting ';'";
|
||||
break;
|
||||
case XML_ERR_ENTITY_LOOP:
|
||||
errmsg = "Detected an entity reference loop\n";
|
||||
errmsg = "Detected an entity reference loop";
|
||||
break;
|
||||
case XML_ERR_ENTITY_NOT_STARTED:
|
||||
errmsg = "EntityValue: \" or ' expected\n";
|
||||
errmsg = "EntityValue: \" or ' expected";
|
||||
break;
|
||||
case XML_ERR_ENTITY_PE_INTERNAL:
|
||||
errmsg = "PEReferences forbidden in internal subset\n";
|
||||
errmsg = "PEReferences forbidden in internal subset";
|
||||
break;
|
||||
case XML_ERR_ENTITY_NOT_FINISHED:
|
||||
errmsg = "EntityValue: \" or ' expected\n";
|
||||
errmsg = "EntityValue: \" or ' expected";
|
||||
break;
|
||||
case XML_ERR_ATTRIBUTE_NOT_STARTED:
|
||||
errmsg = "AttValue: \" or ' expected\n";
|
||||
errmsg = "AttValue: \" or ' expected";
|
||||
break;
|
||||
case XML_ERR_LT_IN_ATTRIBUTE:
|
||||
errmsg = "Unescaped '<' not allowed in attributes values\n";
|
||||
errmsg = "Unescaped '<' not allowed in attributes values";
|
||||
break;
|
||||
case XML_ERR_LITERAL_NOT_STARTED:
|
||||
errmsg = "SystemLiteral \" or ' expected\n";
|
||||
errmsg = "SystemLiteral \" or ' expected";
|
||||
break;
|
||||
case XML_ERR_LITERAL_NOT_FINISHED:
|
||||
errmsg = "Unfinished System or Public ID \" or ' expected\n";
|
||||
errmsg = "Unfinished System or Public ID \" or ' expected";
|
||||
break;
|
||||
case XML_ERR_MISPLACED_CDATA_END:
|
||||
errmsg = "Sequence ']]>' not allowed in content\n";
|
||||
errmsg = "Sequence ']]>' not allowed in content";
|
||||
break;
|
||||
case XML_ERR_URI_REQUIRED:
|
||||
errmsg = "SYSTEM or PUBLIC, the URI is missing\n";
|
||||
errmsg = "SYSTEM or PUBLIC, the URI is missing";
|
||||
break;
|
||||
case XML_ERR_PUBID_REQUIRED:
|
||||
errmsg = "PUBLIC, the Public Identifier is missing\n";
|
||||
errmsg = "PUBLIC, the Public Identifier is missing";
|
||||
break;
|
||||
case XML_ERR_HYPHEN_IN_COMMENT:
|
||||
errmsg = "Comment must not contain '--' (double-hyphen)\n";
|
||||
errmsg = "Comment must not contain '--' (double-hyphen)";
|
||||
break;
|
||||
case XML_ERR_PI_NOT_STARTED:
|
||||
errmsg = "xmlParsePI : no target name\n";
|
||||
errmsg = "xmlParsePI : no target name";
|
||||
break;
|
||||
case XML_ERR_RESERVED_XML_NAME:
|
||||
errmsg = "Invalid PI name\n";
|
||||
errmsg = "Invalid PI name";
|
||||
break;
|
||||
case XML_ERR_NOTATION_NOT_STARTED:
|
||||
errmsg = "NOTATION: Name expected here\n";
|
||||
errmsg = "NOTATION: Name expected here";
|
||||
break;
|
||||
case XML_ERR_NOTATION_NOT_FINISHED:
|
||||
errmsg = "'>' required to close NOTATION declaration\n";
|
||||
errmsg = "'>' required to close NOTATION declaration";
|
||||
break;
|
||||
case XML_ERR_VALUE_REQUIRED:
|
||||
errmsg = "Entity value required\n";
|
||||
errmsg = "Entity value required";
|
||||
break;
|
||||
case XML_ERR_URI_FRAGMENT:
|
||||
errmsg = "Fragment not allowed";
|
||||
break;
|
||||
case XML_ERR_ATTLIST_NOT_STARTED:
|
||||
errmsg = "'(' required to start ATTLIST enumeration\n";
|
||||
errmsg = "'(' required to start ATTLIST enumeration";
|
||||
break;
|
||||
case XML_ERR_NMTOKEN_REQUIRED:
|
||||
errmsg = "NmToken expected in ATTLIST enumeration\n";
|
||||
errmsg = "NmToken expected in ATTLIST enumeration";
|
||||
break;
|
||||
case XML_ERR_ATTLIST_NOT_FINISHED:
|
||||
errmsg = "')' required to finish ATTLIST enumeration\n";
|
||||
errmsg = "')' required to finish ATTLIST enumeration";
|
||||
break;
|
||||
case XML_ERR_MIXED_NOT_STARTED:
|
||||
errmsg = "MixedContentDecl : '|' or ')*' expected\n";
|
||||
errmsg = "MixedContentDecl : '|' or ')*' expected";
|
||||
break;
|
||||
case XML_ERR_PCDATA_REQUIRED:
|
||||
errmsg = "MixedContentDecl : '#PCDATA' expected\n";
|
||||
errmsg = "MixedContentDecl : '#PCDATA' expected";
|
||||
break;
|
||||
case XML_ERR_ELEMCONTENT_NOT_STARTED:
|
||||
errmsg = "ContentDecl : Name or '(' expected\n";
|
||||
errmsg = "ContentDecl : Name or '(' expected";
|
||||
break;
|
||||
case XML_ERR_ELEMCONTENT_NOT_FINISHED:
|
||||
errmsg = "ContentDecl : ',' '|' or ')' expected\n";
|
||||
errmsg = "ContentDecl : ',' '|' or ')' expected";
|
||||
break;
|
||||
case XML_ERR_PEREF_IN_INT_SUBSET:
|
||||
errmsg =
|
||||
"PEReference: forbidden within markup decl in internal subset\n";
|
||||
"PEReference: forbidden within markup decl in internal subset";
|
||||
break;
|
||||
case XML_ERR_GT_REQUIRED:
|
||||
errmsg = "expected '>'\n";
|
||||
errmsg = "expected '>'";
|
||||
break;
|
||||
case XML_ERR_CONDSEC_INVALID:
|
||||
errmsg = "XML conditional section '[' expected\n";
|
||||
errmsg = "XML conditional section '[' expected";
|
||||
break;
|
||||
case XML_ERR_EXT_SUBSET_NOT_FINISHED:
|
||||
errmsg = "Content error in the external subset\n";
|
||||
errmsg = "Content error in the external subset";
|
||||
break;
|
||||
case XML_ERR_CONDSEC_INVALID_KEYWORD:
|
||||
errmsg =
|
||||
"conditional section INCLUDE or IGNORE keyword expected\n";
|
||||
"conditional section INCLUDE or IGNORE keyword expected";
|
||||
break;
|
||||
case XML_ERR_CONDSEC_NOT_FINISHED:
|
||||
errmsg = "XML conditional section not closed\n";
|
||||
errmsg = "XML conditional section not closed";
|
||||
break;
|
||||
case XML_ERR_XMLDECL_NOT_STARTED:
|
||||
errmsg = "Text declaration '<?xml' required\n";
|
||||
errmsg = "Text declaration '<?xml' required";
|
||||
break;
|
||||
case XML_ERR_XMLDECL_NOT_FINISHED:
|
||||
errmsg = "parsing XML declaration: '?>' expected\n";
|
||||
errmsg = "parsing XML declaration: '?>' expected";
|
||||
break;
|
||||
case XML_ERR_EXT_ENTITY_STANDALONE:
|
||||
errmsg = "external parsed entities cannot be standalone\n";
|
||||
errmsg = "external parsed entities cannot be standalone";
|
||||
break;
|
||||
case XML_ERR_ENTITYREF_SEMICOL_MISSING:
|
||||
errmsg = "EntityRef: expecting ';'\n";
|
||||
errmsg = "EntityRef: expecting ';'";
|
||||
break;
|
||||
case XML_ERR_DOCTYPE_NOT_FINISHED:
|
||||
errmsg = "DOCTYPE improperly terminated\n";
|
||||
errmsg = "DOCTYPE improperly terminated";
|
||||
break;
|
||||
case XML_ERR_LTSLASH_REQUIRED:
|
||||
errmsg = "EndTag: '</' not found\n";
|
||||
errmsg = "EndTag: '</' not found";
|
||||
break;
|
||||
case XML_ERR_EQUAL_REQUIRED:
|
||||
errmsg = "expected '='\n";
|
||||
errmsg = "expected '='";
|
||||
break;
|
||||
case XML_ERR_STRING_NOT_CLOSED:
|
||||
errmsg = "String not closed expecting \" or '\n";
|
||||
errmsg = "String not closed expecting \" or '";
|
||||
break;
|
||||
case XML_ERR_STRING_NOT_STARTED:
|
||||
errmsg = "String not started expecting ' or \"\n";
|
||||
errmsg = "String not started expecting ' or \"";
|
||||
break;
|
||||
case XML_ERR_ENCODING_NAME:
|
||||
errmsg = "Invalid XML encoding name\n";
|
||||
errmsg = "Invalid XML encoding name";
|
||||
break;
|
||||
case XML_ERR_STANDALONE_VALUE:
|
||||
errmsg = "standalone accepts only 'yes' or 'no'\n";
|
||||
errmsg = "standalone accepts only 'yes' or 'no'";
|
||||
break;
|
||||
case XML_ERR_DOCUMENT_EMPTY:
|
||||
errmsg = "Document is empty\n";
|
||||
errmsg = "Document is empty";
|
||||
break;
|
||||
case XML_ERR_DOCUMENT_END:
|
||||
errmsg = "Extra content at the end of the document\n";
|
||||
errmsg = "Extra content at the end of the document";
|
||||
break;
|
||||
case XML_ERR_NOT_WELL_BALANCED:
|
||||
errmsg = "chunk is not well balanced\n";
|
||||
errmsg = "chunk is not well balanced";
|
||||
break;
|
||||
case XML_ERR_EXTRA_CONTENT:
|
||||
errmsg = "extra content at the end of well balanced chunk\n";
|
||||
errmsg = "extra content at the end of well balanced chunk";
|
||||
break;
|
||||
case XML_ERR_VERSION_MISSING:
|
||||
errmsg = "Malformed declaration expecting version\n";
|
||||
errmsg = "Malformed declaration expecting version";
|
||||
break;
|
||||
case XML_ERR_NAME_TOO_LONG:
|
||||
errmsg = "Name too long use XML_PARSE_HUGE option\n";
|
||||
errmsg = "Name too long use XML_PARSE_HUGE option";
|
||||
break;
|
||||
#if 0
|
||||
case:
|
||||
errmsg = "\n";
|
||||
errmsg = "";
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
errmsg = "Unregistered error message\n";
|
||||
errmsg = "Unregistered error message";
|
||||
}
|
||||
if (info == NULL)
|
||||
snprintf(errstr, 128, "%s\n", errmsg);
|
||||
else
|
||||
snprintf(errstr, 128, "%s: %%s\n", errmsg);
|
||||
if (ctxt != NULL)
|
||||
ctxt->errNo = error;
|
||||
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
|
||||
XML_ERR_FATAL, NULL, 0, info, NULL, NULL, 0, 0, errmsg,
|
||||
XML_ERR_FATAL, NULL, 0, info, NULL, NULL, 0, 0, &errstr[0],
|
||||
info);
|
||||
if (ctxt != NULL) {
|
||||
ctxt->wellFormed = 0;
|
||||
|
@ -4,7 +4,8 @@
|
||||
./test/errors/content1.xml:7: parser error : expected '>'
|
||||
<!ELEMENT aElement (a |b * >
|
||||
^
|
||||
./test/errors/content1.xml:7: parser error : internal error
|
||||
./test/errors/content1.xml:7: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
|
||||
|
||||
<!ELEMENT aElement (a |b * >
|
||||
^
|
||||
./test/errors/content1.xml:7: parser error : DOCTYPE improperly terminated
|
||||
|
@ -4,7 +4,8 @@
|
||||
./test/errors/content1.xml:7: parser error : expected '>'
|
||||
<!ELEMENT aElement (a |b * >
|
||||
^
|
||||
./test/errors/content1.xml:7: parser error : internal error
|
||||
./test/errors/content1.xml:7: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
|
||||
|
||||
<!ELEMENT aElement (a |b * >
|
||||
^
|
||||
./test/errors/content1.xml:7: parser error : DOCTYPE improperly terminated
|
||||
|
@ -1,4 +1,5 @@
|
||||
Entity: line 1: parser error : internal error
|
||||
Entity: line 1: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
|
||||
|
||||
%defroot;
|
||||
^
|
||||
Entity: line 1:
|
||||
|
@ -1,4 +1,5 @@
|
||||
Entity: line 1: parser error : internal error
|
||||
Entity: line 1: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
|
||||
|
||||
%defroot;
|
||||
^
|
||||
Entity: line 1:
|
||||
|
Loading…
x
Reference in New Issue
Block a user