mirror of
https://github.com/GNOME/libxml2.git
synced 2025-10-16 23:26:56 +08:00
parser: Fix handling of invalid char refs in recovery mode
Revert to the old behavior which handles invalid char refs more
gracefully. Probably regressed with 37c6618b
(version 2.13.0).
This commit is contained in:
7
parser.c
7
parser.c
@@ -2628,14 +2628,13 @@ xmlParseCharRef(xmlParserCtxt *ctxt) {
|
|||||||
xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
|
xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
|
||||||
"xmlParseCharRef: character reference out of bounds\n",
|
"xmlParseCharRef: character reference out of bounds\n",
|
||||||
val);
|
val);
|
||||||
} else if (IS_CHAR(val)) {
|
val = 0xFFFD;
|
||||||
return(val);
|
} else if (!IS_CHAR(val)) {
|
||||||
} else {
|
|
||||||
xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
|
xmlFatalErrMsgInt(ctxt, XML_ERR_INVALID_CHAR,
|
||||||
"xmlParseCharRef: invalid xmlChar value %d\n",
|
"xmlParseCharRef: invalid xmlChar value %d\n",
|
||||||
val);
|
val);
|
||||||
}
|
}
|
||||||
return(0);
|
return(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
19
testparser.c
19
testparser.c
@@ -183,6 +183,24 @@ testUndeclEntInContent(void) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
testInvalidCharRecovery(void) {
|
||||||
|
const char *xml = "<doc></doc>";
|
||||||
|
xmlDoc *doc;
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
|
doc = xmlReadDoc(BAD_CAST xml, NULL, NULL, XML_PARSE_RECOVER);
|
||||||
|
|
||||||
|
if (strcmp((char *) doc->children->children->content, "\x10") != 0) {
|
||||||
|
fprintf(stderr, "Failed to recover from invalid char ref\n");
|
||||||
|
err = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlFreeDoc(doc);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef LIBXML_VALID_ENABLED
|
#ifdef LIBXML_VALID_ENABLED
|
||||||
static void
|
static void
|
||||||
testSwitchDtdExtSubset(void *vctxt, const xmlChar *name ATTRIBUTE_UNUSED,
|
testSwitchDtdExtSubset(void *vctxt, const xmlChar *name ATTRIBUTE_UNUSED,
|
||||||
@@ -1409,6 +1427,7 @@ main(void) {
|
|||||||
err |= testNodeGetContent();
|
err |= testNodeGetContent();
|
||||||
err |= testCFileIO();
|
err |= testCFileIO();
|
||||||
err |= testUndeclEntInContent();
|
err |= testUndeclEntInContent();
|
||||||
|
err |= testInvalidCharRecovery();
|
||||||
#ifdef LIBXML_VALID_ENABLED
|
#ifdef LIBXML_VALID_ENABLED
|
||||||
err |= testSwitchDtd();
|
err |= testSwitchDtd();
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user