Coverage Report

Created: 2026-04-27 06:55

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.6k
exsltNodeSetFunction (xmlXPathParserContextPtr ctxt, int nargs) {
19
13.6k
    if (nargs != 1) {
20
138
  xmlXPathSetArityError(ctxt);
21
138
  return;
22
138
    }
23
13.5k
    if (xmlXPathStackIsNodeSet (ctxt)) {
24
10.2k
  xsltFunctionNodeSet (ctxt, nargs);
25
10.2k
  return;
26
10.2k
    } else {
27
3.29k
  xmlDocPtr fragment;
28
3.29k
  xsltTransformContextPtr tctxt = xsltXPathGetTransformContext(ctxt);
29
3.29k
  xmlNodePtr txt;
30
3.29k
  xmlChar *strval;
31
3.29k
  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.29k
  fragment = xsltCreateRVT(tctxt);
39
3.29k
  if (fragment == NULL) {
40
3
      xsltTransformError(tctxt, NULL, tctxt->inst,
41
3
    "exsltNodeSetFunction: Failed to create a tree fragment.\n");
42
3
      tctxt->state = XSLT_STATE_STOPPED;
43
3
      return;
44
3
  }
45
3.28k
  xsltRegisterLocalRVT(tctxt, fragment);
46
47
3.28k
  strval = xmlXPathPopString (ctxt);
48
49
3.28k
  txt = xmlNewDocText (fragment, strval);
50
3.28k
  xmlAddChild((xmlNodePtr) fragment, txt);
51
3.28k
  obj = xmlXPathNewNodeSet(txt);
52
3.28k
  if (obj == NULL) {
53
28
      xsltTransformError(tctxt, NULL, tctxt->inst,
54
28
    "exsltNodeSetFunction: Failed to create a node set object.\n");
55
28
      tctxt->state = XSLT_STATE_STOPPED;
56
28
  }
57
3.28k
  if (strval != NULL)
58
3.27k
      xmlFree (strval);
59
60
3.28k
  valuePush (ctxt, obj);
61
3.28k
    }
62
13.5k
}
63
64
static void
65
128
exsltObjectTypeFunction (xmlXPathParserContextPtr ctxt, int nargs) {
66
128
    xmlXPathObjectPtr obj, ret;
67
68
128
    if (nargs != 1) {
69
1
  xmlXPathSetArityError(ctxt);
70
1
  return;
71
1
    }
72
73
127
    obj = valuePop(ctxt);
74
75
127
    switch (obj->type) {
76
7
    case XPATH_STRING:
77
7
  ret = xmlXPathNewCString("string");
78
7
  break;
79
97
    case XPATH_NUMBER:
80
97
  ret = xmlXPathNewCString("number");
81
97
  break;
82
13
    case XPATH_BOOLEAN:
83
13
  ret = xmlXPathNewCString("boolean");
84
13
  break;
85
7
    case XPATH_NODESET:
86
7
  ret = xmlXPathNewCString("node-set");
87
7
  break;
88
1
    case XPATH_XSLT_TREE:
89
1
  ret = xmlXPathNewCString("RTF");
90
1
  break;
91
2
    case XPATH_USERS:
92
2
  ret = xmlXPathNewCString("external");
93
2
  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
127
    }
101
127
    xmlXPathFreeObject(obj);
102
127
    valuePush(ctxt, ret);
103
127
}
104
105
106
/**
107
 * exsltCommonRegister:
108
 *
109
 * Registers the EXSLT - Common module
110
 */
111
112
void
113
4
exsltCommonRegister (void) {
114
4
    xsltRegisterExtModuleFunction((const xmlChar *) "node-set",
115
4
          EXSLT_COMMON_NAMESPACE,
116
4
          exsltNodeSetFunction);
117
4
    xsltRegisterExtModuleFunction((const xmlChar *) "object-type",
118
4
          EXSLT_COMMON_NAMESPACE,
119
4
          exsltObjectTypeFunction);
120
4
    xsltRegisterExtModuleElement((const xmlChar *) "document",
121
4
         EXSLT_COMMON_NAMESPACE,
122
4
         xsltDocumentComp,
123
4
         xsltDocumentElem);
124
4
}