mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-23 01:52:48 +03:00
parser: Always decode entities in namespace URIs
Also decode entities in namespace URIs if entity substitution wasn't requested. This should fix some corner cases when comparing namespace URIs. The Namespaces in XML 1.0 spec says: > In a namespace declaration, the URI reference is the normalized value > of the attribute, so replacement of XML character and entity > references has already been done before any comparison. Make the serialization code escape special characters in namespace URIs like in attribute values. This fixes serialization if entities were substituted when parsing. Fixes https://gitlab.gnome.org/GNOME/libxslt/-/issues/106
This commit is contained in:
20
parser.c
20
parser.c
@@ -4280,7 +4280,7 @@ xmlExpandEntitiesInAttValue(xmlParserCtxtPtr ctxt, const xmlChar *str,
|
||||
*/
|
||||
static xmlChar *
|
||||
xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *attlen, int *alloc,
|
||||
int normalize) {
|
||||
int normalize, int isNamespace) {
|
||||
unsigned maxLength = (ctxt->options & XML_PARSE_HUGE) ?
|
||||
XML_MAX_HUGE_LENGTH :
|
||||
XML_MAX_TEXT_LENGTH;
|
||||
@@ -4288,6 +4288,10 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *attlen, int *alloc,
|
||||
xmlChar *ret;
|
||||
int c, l, quote, flags, chunkSize;
|
||||
int inSpace = 1;
|
||||
int replaceEntities;
|
||||
|
||||
/* Always expand namespace URIs */
|
||||
replaceEntities = (ctxt->replaceEntities) || (isNamespace);
|
||||
|
||||
xmlSBufInit(&buf, maxLength);
|
||||
|
||||
@@ -4400,7 +4404,7 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *attlen, int *alloc,
|
||||
if (val == 0)
|
||||
goto error;
|
||||
|
||||
if ((val == '&') && (!ctxt->replaceEntities)) {
|
||||
if ((val == '&') && (!replaceEntities)) {
|
||||
/*
|
||||
* The reparsing will be done in xmlStringGetNodeList()
|
||||
* called by the attribute() function in SAX.c
|
||||
@@ -4438,12 +4442,12 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *attlen, int *alloc,
|
||||
continue;
|
||||
|
||||
if (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY) {
|
||||
if ((ent->content[0] == '&') && (!ctxt->replaceEntities))
|
||||
if ((ent->content[0] == '&') && (!replaceEntities))
|
||||
xmlSBufAddCString(&buf, "&", 5);
|
||||
else
|
||||
xmlSBufAddString(&buf, ent->content, ent->length);
|
||||
inSpace = 0;
|
||||
} else if (ctxt->replaceEntities) {
|
||||
} else if (replaceEntities) {
|
||||
xmlExpandEntityInAttValue(ctxt, &buf, ent->content, ent,
|
||||
normalize, &inSpace, ctxt->inputNr,
|
||||
/* check */ 1);
|
||||
@@ -4544,7 +4548,7 @@ error:
|
||||
xmlChar *
|
||||
xmlParseAttValue(xmlParserCtxtPtr ctxt) {
|
||||
if ((ctxt == NULL) || (ctxt->input == NULL)) return(NULL);
|
||||
return(xmlParseAttValueInternal(ctxt, NULL, NULL, 0));
|
||||
return(xmlParseAttValueInternal(ctxt, NULL, NULL, 0, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -8777,6 +8781,7 @@ xmlParseAttribute2(xmlParserCtxtPtr ctxt,
|
||||
const xmlChar *prefix, *name;
|
||||
xmlChar *val = NULL, *internal_val = NULL;
|
||||
int normalize = 0;
|
||||
int isNamespace;
|
||||
|
||||
*value = NULL;
|
||||
GROW;
|
||||
@@ -8812,7 +8817,10 @@ xmlParseAttribute2(xmlParserCtxtPtr ctxt,
|
||||
if (RAW == '=') {
|
||||
NEXT;
|
||||
SKIP_BLANKS;
|
||||
val = xmlParseAttValueInternal(ctxt, len, alloc, normalize);
|
||||
isNamespace = (((prefix == NULL) && (name == ctxt->str_xmlns)) ||
|
||||
(prefix == ctxt->str_xmlns));
|
||||
val = xmlParseAttValueInternal(ctxt, len, alloc, normalize,
|
||||
isNamespace);
|
||||
if (val == NULL)
|
||||
goto error;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user