Commit f3f7dd4d authored by Alexandre Julliard's avatar Alexandre Julliard

xslt: Import upstream release 1.1.35.

parent a279c278
......@@ -1970,12 +1970,6 @@ xsltGetExtInfo(xsltStylesheetPtr style, const xmlChar * URI)
/************************************************************************
* *
* Test module http://xmlsoft.org/XSLT/ *
* *
************************************************************************/
/************************************************************************
* *
* Test of the extension module API *
* *
************************************************************************/
......
......@@ -246,7 +246,7 @@ XSLTPUBFUN xmlHashTablePtr XSLTCALL
const xmlChar *URI);
/**
* Test module http://xmlsoft.org/XSLT/
* Test of the extension module API
*/
XSLTPUBFUN void XSLTCALL
xsltRegisterTestModule (void);
......
......@@ -178,10 +178,22 @@ xsltDocumentFunctionLoadDocument(xmlXPathParserContextPtr ctxt, xmlChar* URI)
goto out_fragment;
}
#if LIBXML_VERSION >= 20911 || \
defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
xptrctxt->opLimit = ctxt->context->opLimit;
xptrctxt->opCount = ctxt->context->opCount;
xptrctxt->depth = ctxt->context->depth;
resObj = xmlXPtrEval(fragment, xptrctxt);
ctxt->context->opCount = xptrctxt->opCount;
#else
resObj = xmlXPtrEval(fragment, xptrctxt);
xmlXPathFreeContext(xptrctxt);
#endif
xmlXPathFreeContext(xptrctxt);
#endif /* LIBXML_XPTR_ENABLED */
if (resObj == NULL)
goto out_fragment;
......
......@@ -177,7 +177,7 @@ xsltNumberFormatDecimal(xmlBufferPtr buffer,
i = -1;
break;
}
*(--pointer) = val;
*(--pointer) = (xmlChar)val;
}
else {
/*
......@@ -960,7 +960,7 @@ xsltFormatNumberConversion(xsltDecimalFormatPtr self,
xmlChar *nprefix, *nsuffix = NULL;
int prefix_length, suffix_length = 0, nprefix_length, nsuffix_length;
double scale;
int j, len;
int j, len = 0;
int self_grouping_len;
xsltFormatNumberInfo format_info;
/*
......
......@@ -1494,6 +1494,8 @@ xsltNumberComp(xsltStylesheetPtr style, xmlNodePtr cur) {
comp->numdata.groupingCharacterLen = xmlStrlen(prop);
comp->numdata.groupingCharacter =
xsltGetUTF8Char(prop, &(comp->numdata.groupingCharacterLen));
if (comp->numdata.groupingCharacter < 0)
comp->numdata.groupingCharacter = 0;
}
prop = xsltGetCNsProp(style, cur, (const xmlChar *)"grouping-size", XSLT_NAMESPACE);
......
......@@ -22,7 +22,7 @@ extern "C" {
/*
* Interfaces
*/
extern const xmlChar *xsltExtMarker;
XSLTPUBVAR const xmlChar *xsltExtMarker;
XSLTPUBFUN xsltElemPreCompPtr XSLTCALL
xsltDocumentComp (xsltStylesheetPtr style,
......
......@@ -282,7 +282,7 @@ xsltCheckFilename (const char *path)
#if defined(_WIN32) && !defined(__CYGWIN__)
DWORD dwAttrs;
dwAttrs = GetFileAttributes(path);
dwAttrs = GetFileAttributesA(path);
if (dwAttrs != INVALID_FILE_ATTRIBUTES) {
if (dwAttrs & FILE_ATTRIBUTE_DIRECTORY) {
return 2;
......
......@@ -210,6 +210,8 @@ xsltEvalTemplateString(xsltTransformContextPtr ctxt,
{
xmlNodePtr oldInsert, insert = NULL;
xmlChar *ret;
const xmlChar *oldLastText;
int oldLastTextSize, oldLastTextUse;
if ((ctxt == NULL) || (contextNode == NULL) || (inst == NULL) ||
(inst->type != XML_ELEMENT_NODE))
......@@ -233,12 +235,18 @@ xsltEvalTemplateString(xsltTransformContextPtr ctxt,
}
oldInsert = ctxt->insert;
ctxt->insert = insert;
oldLastText = ctxt->lasttext;
oldLastTextSize = ctxt->lasttsize;
oldLastTextUse = ctxt->lasttuse;
/*
* OPTIMIZE TODO: if inst->children consists only of text-nodes.
*/
xsltApplyOneTemplate(ctxt, contextNode, inst->children, NULL, NULL);
ctxt->insert = oldInsert;
ctxt->lasttext = oldLastText;
ctxt->lasttsize = oldLastTextSize;
ctxt->lasttuse = oldLastTextUse;
ret = xmlNodeGetContent(insert);
if (insert != NULL)
......
......@@ -1895,7 +1895,7 @@ static void
xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node,
xsltStackElemPtr params) {
xmlNodePtr copy;
xmlNodePtr delete = NULL, cur;
xmlNodePtr cur;
int nbchild = 0, oldSize;
int childno = 0, oldPos;
xsltTemplatePtr template;
......@@ -1968,54 +1968,13 @@ xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node,
return;
}
/*
* Handling of Elements: first pass, cleanup and counting
* Handling of Elements: first pass, counting
*/
cur = node->children;
while (cur != NULL) {
switch (cur->type) {
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_DOCUMENT_NODE:
case XML_HTML_DOCUMENT_NODE:
case XML_ELEMENT_NODE:
case XML_PI_NODE:
case XML_COMMENT_NODE:
nbchild++;
break;
case XML_DTD_NODE:
/* Unlink the DTD, it's still reachable using doc->intSubset */
if (cur->next != NULL)
cur->next->prev = cur->prev;
if (cur->prev != NULL)
cur->prev->next = cur->next;
break;
default:
#ifdef WITH_XSLT_DEBUG_PROCESS
XSLT_TRACE(ctxt,XSLT_TRACE_PROCESS_NODE,xsltGenericDebug(xsltGenericDebugContext,
"xsltDefaultProcessOneNode: skipping node type %d\n",
cur->type));
#endif
delete = cur;
}
if (IS_XSLT_REAL_NODE(cur))
nbchild++;
cur = cur->next;
if (delete != NULL) {
#ifdef WITH_XSLT_DEBUG_PROCESS
XSLT_TRACE(ctxt,XSLT_TRACE_PROCESS_NODE,xsltGenericDebug(xsltGenericDebugContext,
"xsltDefaultProcessOneNode: removing ignorable blank node\n"));
#endif
xmlUnlinkNode(delete);
xmlFreeNode(delete);
delete = NULL;
}
}
if (delete != NULL) {
#ifdef WITH_XSLT_DEBUG_PROCESS
XSLT_TRACE(ctxt,XSLT_TRACE_PROCESS_NODE,xsltGenericDebug(xsltGenericDebugContext,
"xsltDefaultProcessOneNode: removing ignorable blank node\n"));
#endif
xmlUnlinkNode(delete);
xmlFreeNode(delete);
delete = NULL;
}
/*
......@@ -3672,8 +3631,10 @@ xsltDocumentElem(xsltTransformContextPtr ctxt, xmlNodePtr node,
if (elements != NULL) {
if (style->stripSpaces == NULL)
style->stripSpaces = xmlHashCreate(10);
if (style->stripSpaces == NULL)
if (style->stripSpaces == NULL) {
xmlFree(elements);
return;
}
element = elements;
while (*element != 0) {
......@@ -4864,7 +4825,7 @@ xsltApplyTemplates(xsltTransformContextPtr ctxt, xmlNodePtr node,
xsltStylePreCompPtr comp = (xsltStylePreCompPtr) castedComp;
#endif
int i;
xmlNodePtr cur, delNode = NULL, oldContextNode;
xmlNodePtr cur, oldContextNode;
xmlNodeSetPtr list = NULL, oldList;
xsltStackElemPtr withParams = NULL;
int oldXPProximityPosition, oldXPContextSize;
......@@ -4998,73 +4959,9 @@ xsltApplyTemplates(xsltTransformContextPtr ctxt, xmlNodePtr node,
else
cur = NULL;
while (cur != NULL) {
switch (cur->type) {
case XML_TEXT_NODE:
if ((IS_BLANK_NODE(cur)) &&
(cur->parent != NULL) &&
(cur->parent->type == XML_ELEMENT_NODE) &&
(ctxt->style->stripSpaces != NULL)) {
const xmlChar *val;
if (cur->parent->ns != NULL) {
val = (const xmlChar *)
xmlHashLookup2(ctxt->style->stripSpaces,
cur->parent->name,
cur->parent->ns->href);
if (val == NULL) {
val = (const xmlChar *)
xmlHashLookup2(ctxt->style->stripSpaces,
BAD_CAST "*",
cur->parent->ns->href);
}
} else {
val = (const xmlChar *)
xmlHashLookup2(ctxt->style->stripSpaces,
cur->parent->name, NULL);
}
if ((val != NULL) &&
(xmlStrEqual(val, (xmlChar *) "strip"))) {
delNode = cur;
break;
}
}
/* Intentional fall-through */
case XML_ELEMENT_NODE:
case XML_DOCUMENT_NODE:
case XML_HTML_DOCUMENT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_PI_NODE:
case XML_COMMENT_NODE:
xmlXPathNodeSetAddUnique(list, cur);
break;
case XML_DTD_NODE:
/* Unlink the DTD, it's still reachable
* using doc->intSubset */
if (cur->next != NULL)
cur->next->prev = cur->prev;
if (cur->prev != NULL)
cur->prev->next = cur->next;
break;
case XML_NAMESPACE_DECL:
break;
default:
#ifdef WITH_XSLT_DEBUG_PROCESS
XSLT_TRACE(ctxt,XSLT_TRACE_APPLY_TEMPLATES,xsltGenericDebug(xsltGenericDebugContext,
"xsltApplyTemplates: skipping cur type %d\n",
cur->type));
#endif
delNode = cur;
}
if (IS_XSLT_REAL_NODE(cur))
xmlXPathNodeSetAddUnique(list, cur);
cur = cur->next;
if (delNode != NULL) {
#ifdef WITH_XSLT_DEBUG_PROCESS
XSLT_TRACE(ctxt,XSLT_TRACE_APPLY_TEMPLATES,xsltGenericDebug(xsltGenericDebugContext,
"xsltApplyTemplates: removing ignorable blank cur\n"));
#endif
xmlUnlinkNode(delNode);
xmlFreeNode(delNode);
delNode = NULL;
}
}
}
......@@ -5121,6 +5018,7 @@ xsltApplyTemplates(xsltTransformContextPtr ctxt, xmlNodePtr node,
xmlNodePtr sorts[XSLT_MAX_SORT];
sorts[nbsorts++] = cur;
cur = cur->next;
while (cur) {
......
......@@ -3656,12 +3656,8 @@ xsltPreprocessStylesheet(xsltStylesheetPtr style, xmlNodePtr cur)
(!xsltCheckExtURI(style, cur->ns->href))) {
goto skip_children;
} else if (cur->children != NULL) {
if ((cur->children->type != XML_ENTITY_DECL) &&
(cur->children->type != XML_ENTITY_REF_NODE) &&
(cur->children->type != XML_ENTITY_NODE)) {
cur = cur->children;
continue;
}
cur = cur->children;
continue;
}
skip_children:
......
......@@ -291,6 +291,9 @@ struct _xsltTemplate {
int templMax; /* Size of the templtes stack */
xsltTemplatePtr *templCalledTab; /* templates called */
int *templCountTab; /* .. and how often */
/* Conflict resolution */
int position;
};
/**
......@@ -1500,17 +1503,18 @@ struct _xsltStylesheet {
/*
* Template descriptions.
*/
xsltTemplatePtr templates; /* the ordered list of templates */
void *templatesHash; /* hash table or wherever compiled templates
information is stored */
void *rootMatch; /* template based on / */
void *keyMatch; /* template based on key() */
void *elemMatch; /* template based on * */
void *attrMatch; /* template based on @* */
void *parentMatch; /* template based on .. */
void *textMatch; /* template based on text() */
void *piMatch; /* template based on processing-instruction() */
void *commentMatch; /* template based on comment() */
xsltTemplatePtr templates; /* the ordered list of templates */
xmlHashTablePtr templatesHash; /* hash table or wherever compiled
templates information is stored */
struct _xsltCompMatch *rootMatch; /* template based on / */
struct _xsltCompMatch *keyMatch; /* template based on key() */
struct _xsltCompMatch *elemMatch; /* template based on * */
struct _xsltCompMatch *attrMatch; /* template based on @* */
struct _xsltCompMatch *parentMatch; /* template based on .. */
struct _xsltCompMatch *textMatch; /* template based on text() */
struct _xsltCompMatch *piMatch; /* template based on
processing-instruction() */
struct _xsltCompMatch *commentMatch; /* template based on comment() */
/*
* Namespace aliases.
......
......@@ -20,21 +20,21 @@ extern "C" {
*
* the version string like "1.2.3"
*/
#define LIBXSLT_DOTTED_VERSION "1.1.34"
#define LIBXSLT_DOTTED_VERSION "1.1.35"
/**
* LIBXSLT_VERSION:
*
* the version number: 1.2.3 value is 10203
*/
#define LIBXSLT_VERSION 10134
#define LIBXSLT_VERSION 10135
/**
* LIBXSLT_VERSION_STRING:
*
* the version number string, 1.2.3 value is "10203"
*/
#define LIBXSLT_VERSION_STRING "10134"
#define LIBXSLT_VERSION_STRING "10135"
/**
* LIBXSLT_VERSION_EXTRA:
......
......@@ -346,7 +346,8 @@ xsltDefaultRegion(const xmlChar *localeName) {
void
xsltFreeLocale(xsltLocale locale) {
#ifdef XSLT_LOCALE_POSIX
freelocale(locale);
if (locale != NULL)
freelocale(locale);
#endif
}
......
......@@ -948,17 +948,19 @@ xsltDocumentSortFunction(xmlNodeSetPtr list) {
}
/**
* xsltComputeSortResult:
* xsltComputeSortResultiInternal:
* @ctxt: a XSLT process context
* @sort: node list
* @xfrm: Transform strings according to locale
*
* reorder the current node list accordingly to the set of sorting
* requirement provided by the array of nodes.
*
* Returns a ordered XPath nodeset or NULL in case of error.
*/
xmlXPathObjectPtr *
xsltComputeSortResult(xsltTransformContextPtr ctxt, xmlNodePtr sort) {
static xmlXPathObjectPtr *
xsltComputeSortResultInternal(xsltTransformContextPtr ctxt, xmlNodePtr sort,
int xfrm) {
#ifdef XSLT_REFACTORED
xsltStyleItemSortPtr comp;
#else
......@@ -1045,7 +1047,7 @@ xsltComputeSortResult(xsltTransformContextPtr ctxt, xmlNodePtr sort) {
}
} else {
if (res->type == XPATH_STRING) {
if (comp->locale != (xsltLocale)0) {
if ((xfrm) && (comp->locale != (xsltLocale)0)) {
xmlChar *str = res->stringval;
res->stringval = (xmlChar *) xsltStrxfrm(comp->locale, str);
xmlFree(str);
......@@ -1076,6 +1078,21 @@ xsltComputeSortResult(xsltTransformContextPtr ctxt, xmlNodePtr sort) {
}
/**
* xsltComputeSortResult:
* @ctxt: a XSLT process context
* @sort: node list
*
* reorder the current node list accordingly to the set of sorting
* requirement provided by the array of nodes.
*
* Returns a ordered XPath nodeset or NULL in case of error.
*/
xmlXPathObjectPtr *
xsltComputeSortResult(xsltTransformContextPtr ctxt, xmlNodePtr sort) {
return xsltComputeSortResultInternal(ctxt, sort, /* xfrm */ 0);
}
/**
* xsltDefaultSortFunction:
* @ctxt: a XSLT process context
* @sorts: array of sort nodes
......@@ -1102,7 +1119,8 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
int depth;
xmlNodePtr node;
xmlXPathObjectPtr tmp;
int tempstype[XSLT_MAX_SORT], temporder[XSLT_MAX_SORT];
int tempstype[XSLT_MAX_SORT], temporder[XSLT_MAX_SORT],
templang[XSLT_MAX_SORT];
if ((ctxt == NULL) || (sorts == NULL) || (nbsorts <= 0) ||
(nbsorts >= XSLT_MAX_SORT))
......@@ -1124,7 +1142,7 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
comp->stype =
xsltEvalAttrValueTemplate(ctxt, sorts[j],
(const xmlChar *) "data-type",
XSLT_NAMESPACE);
NULL);
if (comp->stype != NULL) {
tempstype[j] = 1;
if (xmlStrEqual(comp->stype, (const xmlChar *) "text"))
......@@ -1143,7 +1161,7 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
if ((comp->order == NULL) && (comp->has_order != 0)) {
comp->order = xsltEvalAttrValueTemplate(ctxt, sorts[j],
(const xmlChar *) "order",
XSLT_NAMESPACE);
NULL);
if (comp->order != NULL) {
temporder[j] = 1;
if (xmlStrEqual(comp->order, (const xmlChar *) "ascending"))
......@@ -1159,11 +1177,23 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
}
}
}
templang[j] = 0;
if ((comp->lang == NULL) && (comp->has_lang != 0)) {
xmlChar *lang = xsltEvalAttrValueTemplate(ctxt, sorts[j],
(xmlChar *) "lang",
NULL);
if (lang != NULL) {
templang[j] = 1;
comp->locale = xsltNewLocale(lang);
xmlFree(lang);
}
}
}
len = list->nodeNr;
resultsTab[0] = xsltComputeSortResult(ctxt, sorts[0]);
resultsTab[0] = xsltComputeSortResultInternal(ctxt, sorts[0],
/* xfrm */ 1);
for (i = 1;i < XSLT_MAX_SORT;i++)
resultsTab[i] = NULL;
......@@ -1173,7 +1203,7 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
descending = comp->descending;
number = comp->number;
if (results == NULL)
return;
goto cleanup;
/* Shell's sort of node-set */
for (incr = len / 2; incr > 0; incr /= 2) {
......@@ -1234,8 +1264,10 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
* full set, this might be optimized ... or not
*/
if (resultsTab[depth] == NULL)
resultsTab[depth] = xsltComputeSortResult(ctxt,
sorts[depth]);
resultsTab[depth] =
xsltComputeSortResultInternal(ctxt,
sorts[depth],
/* xfrm */ 1);
res = resultsTab[depth];
if (res == NULL)
break;
......@@ -1315,6 +1347,7 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
}
}
cleanup:
for (j = 0; j < nbsorts; j++) {
comp = sorts[j]->psvi;
if (tempstype[j] == 1) {
......@@ -1327,6 +1360,10 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
xmlFree((void *)(comp->order));
comp->order = NULL;
}
if (templang[j] == 1) {
xsltFreeLocale(comp->locale);
comp->locale = (xsltLocale)0;
}
if (resultsTab[j] != NULL) {
for (i = 0;i < len;i++)
xmlXPathFreeObject(resultsTab[j][i]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment