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

View File

@@ -6867,42 +6867,19 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {
if (NXT(1) == '#') {
int i = 0;
xmlChar out[16];
int hex = NXT(2);
int value = xmlParseCharRef(ctxt);
if (value == 0)
return;
if (ctxt->charset != XML_CHAR_ENCODING_UTF8) {
/*
* So we are using non-UTF-8 buffers
* Check that the char fit on 8bits, if not
* generate a CharRef.
*/
if (value <= 0xFF) {
out[0] = value;
out[1] = 0;
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);
}
/*
* 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;
}