1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-24 13:33:01 +03:00

parser: Always create UTF-8 in xmlParseReference

It seems that this code path could only be triggered after an encoding
error in recovery mode. Creating char-ref nodes is unnecessary and
typically unexpected.
This commit is contained in:
Nick Wellnhofer
2023-08-08 15:19:44 +02:00
parent 131d0dc0a7
commit d38e73f91e
2 changed files with 10 additions and 36 deletions

5
SAX2.c
View File

@@ -2503,10 +2503,7 @@ xmlSAX2Reference(void *ctx, const xmlChar *name)
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2Reference(%s)\n", name); "SAX.xmlSAX2Reference(%s)\n", name);
#endif #endif
if (name[0] == '#') ret = xmlNewReference(ctxt->myDoc, name);
ret = xmlNewCharRef(ctxt->myDoc, name);
else
ret = xmlNewReference(ctxt->myDoc, name);
#ifdef DEBUG_SAX_TREE #ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"add xmlSAX2Reference %s to %s \n", name, ctxt->node->name); "add xmlSAX2Reference %s to %s \n", name, ctxt->node->name);

View File

@@ -6867,42 +6867,19 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {
if (NXT(1) == '#') { if (NXT(1) == '#') {
int i = 0; int i = 0;
xmlChar out[16]; xmlChar out[16];
int hex = NXT(2);
int value = xmlParseCharRef(ctxt); int value = xmlParseCharRef(ctxt);
if (value == 0) if (value == 0)
return; return;
if (ctxt->charset != XML_CHAR_ENCODING_UTF8) {
/* /*
* So we are using non-UTF-8 buffers * Just encode the value in UTF-8
* Check that the char fit on 8bits, if not */
* generate a CharRef. COPY_BUF(0, out, i, value);
*/ out[i] = 0;
if (value <= 0xFF) { if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL) &&
out[0] = value; (!ctxt->disableSAX))
out[1] = 0; ctxt->sax->characters(ctxt->userData, out, i);
if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL) &&
(!ctxt->disableSAX))
ctxt->sax->characters(ctxt->userData, out, 1);
} else {
if ((hex == 'x') || (hex == 'X'))
snprintf((char *)out, sizeof(out), "#x%X", value);
else
snprintf((char *)out, sizeof(out), "#%d", value);
if ((ctxt->sax != NULL) && (ctxt->sax->reference != NULL) &&
(!ctxt->disableSAX))
ctxt->sax->reference(ctxt->userData, out);
}
} else {
/*
* Just encode the value in UTF-8
*/
COPY_BUF(0 ,out, i, value);
out[i] = 0;
if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL) &&
(!ctxt->disableSAX))
ctxt->sax->characters(ctxt->userData, out, i);
}
return; return;
} }