Coverage Report

Created: 2026-05-30 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxslt/libexslt/common.c
Line
Count
Source
1
#define IN_LIBEXSLT
2
#include "libexslt/libexslt.h"
3
4
#include <libxml/tree.h>
5
#include <libxml/xpath.h>
6
#include <libxml/xpathInternals.h>
7
8
#include <libxslt/xsltutils.h>
9
#include <libxslt/xsltInternals.h>
10
#include <libxslt/extensions.h>
11
#include <libxslt/transform.h>
12
#include <libxslt/extra.h>
13
#include <libxslt/preproc.h>
14
15
#include "exslt.h"
16
17
static void
18
13.4k
exsltNodeSetFunction (xmlXPathParserContextPtr ctxt, int nargs) {
19
13.4k
    if (nargs != 1) {
20
169
  xmlXPathSetArityError(ctxt);
21
169
  return;
22
169
    }
23
13.2k
    if (xmlXPathStackIsNodeSet (ctxt)) {
24
9.77k
  xsltFunctionNodeSet (ctxt, nargs);
25
9.77k
  return;
26
9.77k
    } else {
27
3.46k
  xmlDocPtr fragment;
28
3.46k
  xsltTransformContextPtr tctxt = xsltXPathGetTransformContext(ctxt);
29
3.46k
  xmlNodePtr txt;
30
3.46k
  xmlChar *strval;
31
3.46k
  xmlXPathObjectPtr obj;
32
  /*
33
  * SPEC EXSLT:
34
  * "You can also use this function to turn a string into a text
35
  * node, which is helpful if you want to pass a string to a
36
  * function that only accepts a node-set."
37
  */
38
3.46k
  fragment = xsltCreateRVT(tctxt);
39
3.46k
  if (fragment == NULL) {
40
4
      xsltTransformError(tctxt, NULL, tctxt->inst,
41
4
    "exsltNodeSetFunction: Failed to create a tree fragment.\n");
42
4
      tctxt->state = XSLT_STATE_STOPPED;
43
4
      return;
44
4
  }
45
3.45k
  xsltRegisterLocalRVT(tctxt, fragment);
46
47
3.45k
  strval = xmlXPathPopString (ctxt);
48
49
3.45k
  txt = xmlNewDocText (fragment, strval);
50
3.45k
  xmlAddChild((xmlNodePtr) fragment, txt);
51
3.45k
  obj = xmlXPathNewNodeSet(txt);
52
3.45k
  if (obj == NULL) {
53
27
      xsltTransformError(tctxt, NULL, tctxt->inst,
54
27
    "exsltNodeSetFunction: Failed to create a node set object.\n");
55
27
      tctxt->state = XSLT_STATE_STOPPED;
56
27
  }
57
3.45k
  if (strval != NULL)
58
3.44k
      xmlFree (strval);
59
60
3.45k
  valuePush (ctxt, obj);
61
3.45k
    }
62
13.2k
}
63
64
static void
65
190
exsltObjectTypeFunction (xmlXPathParserContextPtr ctxt, int nargs) {
66
190
    xmlXPathObjectPtr obj, ret;
67
68
190
    if (nargs != 1) {
69
0
  xmlXPathSetArityError(ctxt);
70
0
  return;
71
0
    }
72
73
190
    obj = valuePop(ctxt);
74
75
190
    switch (obj->type) {
76
5
    case XPATH_STRING:
77
5
  ret = xmlXPathNewCString("string");
78
5
  break;
79
91
    case XPATH_NUMBER:
80
91
  ret = xmlXPathNewCString("number");
81
91
  break;
82
17
    case XPATH_BOOLEAN:
83
17
  ret = xmlXPathNewCString("boolean");
84
17
  break;
85
72
    case XPATH_NODESET:
86
72
  ret = xmlXPathNewCString("node-set");
87
72
  break;
88
2
    case XPATH_XSLT_TREE:
89
2
  ret = xmlXPathNewCString("RTF");
90
2
  break;
91
3
    case XPATH_USERS:
92
3
  ret = xmlXPathNewCString("external");
93
3
  break;
94
0
    default:
95
0
  xsltGenericError(xsltGenericErrorContext,
96
0
    "object-type() invalid arg\n");
97
0
  ctxt->error = XPATH_INVALID_TYPE;
98
0
  xmlXPathFreeObject(obj);
99
0
  return;
100
190
    }
101
190
    xmlXPathFreeObject(obj);
102
190
    valuePush(ctxt, ret);
103
190
}
104
105
106
/**
107
 * exsltCommonRegister:
108
 *
109
 * Registers the EXSLT - Common module
110
 */
111
112
void
113
2
exsltCommonRegister (void) {
114
2
    xsltRegisterExtModuleFunction((const xmlChar *) "node-set",
115
2
          EXSLT_COMMON_NAMESPACE,
116
2
          exsltNodeSetFunction);
117
2
    xsltRegisterExtModuleFunction((const xmlChar *) "object-type",
118
2
          EXSLT_COMMON_NAMESPACE,
119
2
          exsltObjectTypeFunction);
120
2
    xsltRegisterExtModuleElement((const xmlChar *) "document",
121
2
         EXSLT_COMMON_NAMESPACE,
122
2
         xsltDocumentComp,
123
2
         xsltDocumentElem);
124
2
}