Coverage Report

Created: 2026-01-10 06:08

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
12.1k
exsltNodeSetFunction (xmlXPathParserContextPtr ctxt, int nargs) {
19
12.1k
    if (nargs != 1) {
20
93
  xmlXPathSetArityError(ctxt);
21
93
  return;
22
93
    }
23
12.0k
    if (xmlXPathStackIsNodeSet (ctxt)) {
24
9.16k
  xsltFunctionNodeSet (ctxt, nargs);
25
9.16k
  return;
26
9.16k
    } else {
27
2.92k
  xmlDocPtr fragment;
28
2.92k
  xsltTransformContextPtr tctxt = xsltXPathGetTransformContext(ctxt);
29
2.92k
  xmlNodePtr txt;
30
2.92k
  xmlChar *strval;
31
2.92k
  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
2.92k
  fragment = xsltCreateRVT(tctxt);
39
2.92k
  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
2.92k
  xsltRegisterLocalRVT(tctxt, fragment);
46
47
2.92k
  strval = xmlXPathPopString (ctxt);
48
49
2.92k
  txt = xmlNewDocText (fragment, strval);
50
2.92k
  xmlAddChild((xmlNodePtr) fragment, txt);
51
2.92k
  obj = xmlXPathNewNodeSet(txt);
52
2.92k
  if (obj == NULL) {
53
36
      xsltTransformError(tctxt, NULL, tctxt->inst,
54
36
    "exsltNodeSetFunction: Failed to create a node set object.\n");
55
36
      tctxt->state = XSLT_STATE_STOPPED;
56
36
  }
57
2.92k
  if (strval != NULL)
58
2.90k
      xmlFree (strval);
59
60
2.92k
  valuePush (ctxt, obj);
61
2.92k
    }
62
12.0k
}
63
64
static void
65
118
exsltObjectTypeFunction (xmlXPathParserContextPtr ctxt, int nargs) {
66
118
    xmlXPathObjectPtr obj, ret;
67
68
118
    if (nargs != 1) {
69
0
  xmlXPathSetArityError(ctxt);
70
0
  return;
71
0
    }
72
73
118
    obj = valuePop(ctxt);
74
75
118
    switch (obj->type) {
76
10
    case XPATH_STRING:
77
10
  ret = xmlXPathNewCString("string");
78
10
  break;
79
51
    case XPATH_NUMBER:
80
51
  ret = xmlXPathNewCString("number");
81
51
  break;
82
2
    case XPATH_BOOLEAN:
83
2
  ret = xmlXPathNewCString("boolean");
84
2
  break;
85
47
    case XPATH_NODESET:
86
47
  ret = xmlXPathNewCString("node-set");
87
47
  break;
88
2
    case XPATH_XSLT_TREE:
89
2
  ret = xmlXPathNewCString("RTF");
90
2
  break;
91
6
    case XPATH_USERS:
92
6
  ret = xmlXPathNewCString("external");
93
6
  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
118
    }
101
118
    xmlXPathFreeObject(obj);
102
118
    valuePush(ctxt, ret);
103
118
}
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
}