leptris 1.9.320.0-arm-linux → 1.9.322.0-arm-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/Rakefile +1 -1
- data/lib/leptris/version.rb +1 -1
- data/lib/leptris/xml/ffi.rb +15 -0
- data/lib/leptris/xml/xsd.rb +58 -6
- data/lib/libleptris.so +0 -0
- data/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +35 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/cli/commands/validate.c +45 -3
- data/vendor-src/libleptris/src/CMakeLists.txt +2 -0
- data/vendor-src/libleptris/src/include/leptris.h +22 -0
- data/vendor-src/libleptris/src/leptris/xsd/compile.c +309 -1
- data/vendor-src/libleptris/src/leptris/xsd/content_model.c +232 -0
- data/vendor-src/libleptris/src/leptris/xsd/validate.c +287 -0
- data/vendor-src/libleptris/src/leptris/xsd/xsd_internal.h +48 -0
- data/vendor-src/libleptris/test/cli/test_cli.cpp +34 -0
- data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +253 -0
- data/vendor-src/libleptris/vcpkg.json +1 -1
- metadata +3 -1
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/* xsd/validate.c — #1075 slice 4: instance-document validation.
|
|
2
|
+
*
|
|
3
|
+
* Walks an instance tree against the compiled schema: element
|
|
4
|
+
* declarations resolve by local name (global declarations), their
|
|
5
|
+
* types drive attribute checking (declared rows, required use),
|
|
6
|
+
* text-content lexical checks (builtins + user simpleTypes), and
|
|
7
|
+
* child-sequence content-model checks (slice 3's NFA). Failures
|
|
8
|
+
* accumulate in the schema-owned error list — the RNG accessor
|
|
9
|
+
* pattern: validate returns 1/0, errors enumerate every miss.
|
|
10
|
+
*/
|
|
11
|
+
#include <stdio.h>
|
|
12
|
+
#include <stdlib.h>
|
|
13
|
+
#include <string.h>
|
|
14
|
+
|
|
15
|
+
#include "../../include/leptris.h"
|
|
16
|
+
#include "xsd_internal.h"
|
|
17
|
+
|
|
18
|
+
extern int xsd_content_valid(struct leptris_xsd_schema* s, XsdCm* model,
|
|
19
|
+
const char* target_ns,
|
|
20
|
+
const char* const* names,
|
|
21
|
+
const char* const* ns_uris, size_t count);
|
|
22
|
+
extern int xsd_builtin_valid(const char* type, const char* v);
|
|
23
|
+
extern int xsd_simple_valid(const XsdSimple* simple, const char* v);
|
|
24
|
+
|
|
25
|
+
struct xsd_error {
|
|
26
|
+
char* text;
|
|
27
|
+
struct xsd_error* next;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
struct leptris_xsd_schema; /* opaque here; compile.c owns the struct */
|
|
31
|
+
|
|
32
|
+
/* The validator reaches the compiled model through accessors the
|
|
33
|
+
* compiler exports (compile.c defines the struct). */
|
|
34
|
+
extern const XsdElementDecl* xsd_find_element(
|
|
35
|
+
struct leptris_xsd_schema* s, const char* name);
|
|
36
|
+
extern XsdCm* xsd_find_complex(struct leptris_xsd_schema* s,
|
|
37
|
+
const char* type_name);
|
|
38
|
+
extern const XsdSimple* xsd_find_simple_pub(
|
|
39
|
+
struct leptris_xsd_schema* s, const char* name);
|
|
40
|
+
extern const char* xsd_target_ns(struct leptris_xsd_schema* s);
|
|
41
|
+
extern const XsdTypeAttrs* xsd_find_type_attrs(
|
|
42
|
+
struct leptris_xsd_schema* s, const char* type_name);
|
|
43
|
+
|
|
44
|
+
/* ---- error list ---------------------------------------------------- */
|
|
45
|
+
|
|
46
|
+
static void verr(struct leptris_xsd_schema* s, const char* fmt,
|
|
47
|
+
const char* a, const char* b);
|
|
48
|
+
struct xsd_validator {
|
|
49
|
+
struct leptris_xsd_schema* s;
|
|
50
|
+
struct xsd_error* errors;
|
|
51
|
+
struct xsd_error* tail;
|
|
52
|
+
size_t count;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
static void verr_push(struct xsd_validator* v, const char* msg) {
|
|
56
|
+
struct xsd_error* e = (struct xsd_error*)malloc(sizeof(*e));
|
|
57
|
+
if (!e) return;
|
|
58
|
+
size_t n = strlen(msg) + 1;
|
|
59
|
+
e->text = (char*)malloc(n);
|
|
60
|
+
if (!e->text) {
|
|
61
|
+
free(e);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
memcpy(e->text, msg, n);
|
|
65
|
+
e->next = NULL;
|
|
66
|
+
if (v->tail)
|
|
67
|
+
v->tail->next = e;
|
|
68
|
+
else
|
|
69
|
+
v->errors = e;
|
|
70
|
+
v->tail = e;
|
|
71
|
+
v->count++;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static void verrf(struct xsd_validator* v, const char* what,
|
|
75
|
+
const char* name, const char* detail) {
|
|
76
|
+
/* "element 'x': detail" — bounded composition */
|
|
77
|
+
char buf[256];
|
|
78
|
+
int w = snprintf(buf, sizeof(buf), "%s '%s': %s", what,
|
|
79
|
+
name ? name : "?", detail ? detail : "invalid");
|
|
80
|
+
(void)w;
|
|
81
|
+
verr_push(v, buf);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* ---- lexical helpers ---------------------------------------------- */
|
|
85
|
+
|
|
86
|
+
static int text_valid(struct xsd_validator* v,
|
|
87
|
+
struct leptris_xsd_schema* s, const char* type,
|
|
88
|
+
const char* lexical, const char* what,
|
|
89
|
+
const char* name) {
|
|
90
|
+
if (!type) return 1;
|
|
91
|
+
int r;
|
|
92
|
+
if (strncmp(type, "xs:", 3) == 0)
|
|
93
|
+
r = xsd_builtin_valid(type, lexical);
|
|
94
|
+
else {
|
|
95
|
+
const XsdSimple* st = xsd_find_simple_pub(s, type);
|
|
96
|
+
if (!st) return 1; /* unresolved: accept */
|
|
97
|
+
r = xsd_simple_valid(st, lexical);
|
|
98
|
+
}
|
|
99
|
+
if (r == 0) {
|
|
100
|
+
verrf(v, what, name, "lexical value does not match its type");
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
return 1;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/* One element: attributes, text, children. */
|
|
107
|
+
static void validate_element(struct xsd_validator* v,
|
|
108
|
+
struct leptris_xsd_schema* s,
|
|
109
|
+
LeptrisElement elem, int depth);
|
|
110
|
+
|
|
111
|
+
static void validate_children(struct xsd_validator* v,
|
|
112
|
+
struct leptris_xsd_schema* s,
|
|
113
|
+
LeptrisElement elem, XsdCm* ct) {
|
|
114
|
+
XsdCm* model = ct->first_child;
|
|
115
|
+
if (!model) return;
|
|
116
|
+
/* collect child names + uris */
|
|
117
|
+
size_t n = 0;
|
|
118
|
+
for (LeptrisNodeRef c =
|
|
119
|
+
leptris_node_first_child(leptris_element_as_node(elem));
|
|
120
|
+
c; c = leptris_node_next_sibling(c))
|
|
121
|
+
if (leptris_node_get_type(c) == LEPTRIS_NODE_TYPE_ELEMENT) n++;
|
|
122
|
+
if (!n) return;
|
|
123
|
+
const char** names = (const char**)malloc(n * sizeof(char*));
|
|
124
|
+
const char** uris = (const char**)calloc(n, sizeof(char*));
|
|
125
|
+
if (!names || !uris) {
|
|
126
|
+
free(names);
|
|
127
|
+
free(uris);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
size_t i = 0;
|
|
131
|
+
for (LeptrisNodeRef c =
|
|
132
|
+
leptris_node_first_child(leptris_element_as_node(elem));
|
|
133
|
+
c; c = leptris_node_next_sibling(c)) {
|
|
134
|
+
if (leptris_node_get_type(c) != LEPTRIS_NODE_TYPE_ELEMENT)
|
|
135
|
+
continue;
|
|
136
|
+
LeptrisElement ce = (LeptrisElement)c;
|
|
137
|
+
const char* local = NULL, *prefix = NULL, *uri = NULL;
|
|
138
|
+
leptris_element_expanded_name(ce, &local, &prefix, &uri);
|
|
139
|
+
names[i] = local ? local : "";
|
|
140
|
+
uris[i] = uri;
|
|
141
|
+
i++;
|
|
142
|
+
}
|
|
143
|
+
int ok = xsd_content_valid(s, model, xsd_target_ns(s), names, uris,
|
|
144
|
+
n);
|
|
145
|
+
free(names);
|
|
146
|
+
free(uris);
|
|
147
|
+
if (!ok) {
|
|
148
|
+
const char* local = NULL;
|
|
149
|
+
leptris_element_expanded_name(elem, &local, NULL, NULL);
|
|
150
|
+
verrf(v, "element", local, "children do not match the content model");
|
|
151
|
+
}
|
|
152
|
+
/* recurse; local particles carry types (first-name-match DFS —
|
|
153
|
+
* position-exact particle typing arrives with the NFA trace). */
|
|
154
|
+
for (LeptrisNodeRef c =
|
|
155
|
+
leptris_node_first_child(leptris_element_as_node(elem));
|
|
156
|
+
c; c = leptris_node_next_sibling(c)) {
|
|
157
|
+
LeptrisElement ce = (LeptrisElement)c;
|
|
158
|
+
const char* cl = NULL, *cp = NULL, *cu = NULL;
|
|
159
|
+
leptris_element_expanded_name(ce, &cl, &cp, &cu);
|
|
160
|
+
if (cl && !xsd_find_element(s, cl) && model) {
|
|
161
|
+
const char* ptype = NULL;
|
|
162
|
+
XsdCm* stack[64];
|
|
163
|
+
int sp = 0;
|
|
164
|
+
stack[sp++] = model;
|
|
165
|
+
while (sp > 0 && ptype == NULL) {
|
|
166
|
+
XsdCm* p = stack[--sp];
|
|
167
|
+
for (; p; p = p->next) {
|
|
168
|
+
if (p->kind == XSD_CM_ELEMENT && p->name &&
|
|
169
|
+
strcmp(p->name, cl) == 0 && p->type) {
|
|
170
|
+
ptype = p->type;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
if (sp < 64 && p->first_child)
|
|
174
|
+
stack[sp++] = p->first_child;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (ptype) {
|
|
178
|
+
const char* text = leptris_element_text(ce);
|
|
179
|
+
if (text && *text)
|
|
180
|
+
text_valid(v, s, ptype, text, "element", cl);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (leptris_node_get_type(c) != LEPTRIS_NODE_TYPE_ELEMENT)
|
|
184
|
+
continue;
|
|
185
|
+
validate_element(v, s, ce, 0);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
static void validate_attributes(struct xsd_validator* v,
|
|
190
|
+
struct leptris_xsd_schema* s,
|
|
191
|
+
LeptrisElement elem,
|
|
192
|
+
const XsdTypeAttrs* ta) {
|
|
193
|
+
if (!ta) return;
|
|
194
|
+
/* declared rows: present? value typed? */
|
|
195
|
+
for (XsdAttrDecl* a = ta->attrs; a; a = a->next) {
|
|
196
|
+
const char* val = leptris_element_attribute(elem, a->name);
|
|
197
|
+
if (!val) {
|
|
198
|
+
/* lenient: the qualified spelling (#1586 semantics) */
|
|
199
|
+
for (LeptrisAttribute at =
|
|
200
|
+
leptris_element_first_attribute(elem);
|
|
201
|
+
at; at = leptris_attribute_next(at)) {
|
|
202
|
+
const char* qn = leptris_attribute_get_name(at);
|
|
203
|
+
const char* colon = qn ? strchr(qn, ':') : NULL;
|
|
204
|
+
if (qn && colon && strcmp(colon + 1, a->name) == 0) {
|
|
205
|
+
val = leptris_attribute_get_value(elem, at);
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
if (qn && !colon && strcmp(qn, a->name) == 0) {
|
|
209
|
+
val = leptris_attribute_get_value(elem, at);
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (!val) {
|
|
215
|
+
if (a->required)
|
|
216
|
+
verrf(v, "attribute", a->name, "required but absent");
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
text_valid(v, s, a->type, val, "attribute", a->name);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
static void validate_element(struct xsd_validator* v,
|
|
224
|
+
struct leptris_xsd_schema* s,
|
|
225
|
+
LeptrisElement elem, int depth) {
|
|
226
|
+
if (depth > 64) return;
|
|
227
|
+
const char* local = NULL, *prefix = NULL, *uri = NULL;
|
|
228
|
+
leptris_element_expanded_name(elem, &local, &prefix, &uri);
|
|
229
|
+
if (!local) return;
|
|
230
|
+
const XsdElementDecl* d = xsd_find_element(s, local);
|
|
231
|
+
if (!d) return; /* undeclared: lax at this depth (strict later) */
|
|
232
|
+
|
|
233
|
+
if (!d->type) return; /* anyType */
|
|
234
|
+
|
|
235
|
+
XsdCm* ct = xsd_find_complex(s, d->type);
|
|
236
|
+
if (ct) {
|
|
237
|
+
validate_attributes(v, s, elem, xsd_find_type_attrs(s, d->type));
|
|
238
|
+
validate_children(v, s, elem, ct);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/* simple-typed element: text must be lexically valid */
|
|
243
|
+
if (strncmp(d->type, "xs:", 3) == 0 ||
|
|
244
|
+
xsd_find_simple_pub(s, d->type)) {
|
|
245
|
+
const char* text = leptris_element_text(elem);
|
|
246
|
+
if (text && *text)
|
|
247
|
+
text_valid(v, s, d->type, text, "element", local);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
struct xsd_validator* xsd_validator_new(struct leptris_xsd_schema* s) {
|
|
252
|
+
struct xsd_validator* v =
|
|
253
|
+
(struct xsd_validator*)calloc(1, sizeof(*v));
|
|
254
|
+
if (v) v->s = s;
|
|
255
|
+
return v;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
void xsd_validator_free(struct xsd_validator* v) {
|
|
259
|
+
if (!v) return;
|
|
260
|
+
struct xsd_error* e = v->errors;
|
|
261
|
+
while (e) {
|
|
262
|
+
struct xsd_error* n = e->next;
|
|
263
|
+
free(e->text);
|
|
264
|
+
free(e);
|
|
265
|
+
e = n;
|
|
266
|
+
}
|
|
267
|
+
free(v);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
int xsd_validator_run(struct xsd_validator* v, LeptrisDocument doc) {
|
|
271
|
+
if (!v || !doc) return -1;
|
|
272
|
+
LeptrisElement root = leptris_document_root(doc);
|
|
273
|
+
if (!root) return -1;
|
|
274
|
+
validate_element(v, v->s, root, 0);
|
|
275
|
+
return v->count == 0 ? 1 : 0;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
size_t xsd_validator_error_count(struct xsd_validator* v) {
|
|
279
|
+
return v ? v->count : 0;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const char* xsd_validator_error_at(struct xsd_validator* v, size_t i) {
|
|
283
|
+
if (!v) return NULL;
|
|
284
|
+
struct xsd_error* e = v->errors;
|
|
285
|
+
for (size_t k = 0; e && k < i; k++) e = e->next;
|
|
286
|
+
return e ? e->text : NULL;
|
|
287
|
+
}
|
|
@@ -37,7 +37,55 @@ typedef struct xsd_simple {
|
|
|
37
37
|
struct xsd_simple* next;
|
|
38
38
|
} XsdSimple;
|
|
39
39
|
|
|
40
|
+
/* Content-model node: a particle (element ref / wildcard) or a
|
|
41
|
+
* group (sequence | choice | all). Owned by the schema; freed
|
|
42
|
+
* with the schema. */
|
|
43
|
+
typedef enum {
|
|
44
|
+
XSD_CM_ELEMENT = 0,
|
|
45
|
+
XSD_CM_ANY,
|
|
46
|
+
XSD_CM_SEQ,
|
|
47
|
+
XSD_CM_CHOICE,
|
|
48
|
+
XSD_CM_ALL
|
|
49
|
+
} XsdCmKind;
|
|
50
|
+
|
|
51
|
+
typedef struct xsd_cm {
|
|
52
|
+
XsdCmKind kind;
|
|
53
|
+
char* name; /* CM_ELEMENT: child element local name */
|
|
54
|
+
char* type; /* CM_ELEMENT: the particle's type ref, if any */
|
|
55
|
+
char* ns; /* CM_ELEMENT: expected namespace (NULL = unqualified) */
|
|
56
|
+
char* any_ns; /* CM_ANY: the namespace attribute grammar */
|
|
57
|
+
int process_skip; /* CM_ANY: processContents="skip" or "lax" */
|
|
58
|
+
int min, max; /* occurrence bounds; max < 0 = unbounded */
|
|
59
|
+
struct xsd_cm* first_child; /* group children list */
|
|
60
|
+
struct xsd_cm* next; /* sibling link within the parent group */
|
|
61
|
+
} XsdCm;
|
|
62
|
+
|
|
63
|
+
/* A top-level xs:element declaration (slice 3: name + type ref). */
|
|
64
|
+
typedef struct xsd_element_decl {
|
|
65
|
+
char* name;
|
|
66
|
+
char* type; /* "xs:string"-style builtin or a local type name */
|
|
67
|
+
struct xsd_element_decl* next;
|
|
68
|
+
} XsdElementDecl;
|
|
69
|
+
|
|
70
|
+
typedef struct xsd_attr_decl {
|
|
71
|
+
char* name; /* attribute local name */
|
|
72
|
+
char* type; /* builtin ref or local simpleType name (NULL=anySimple) */
|
|
73
|
+
int required;
|
|
74
|
+
struct xsd_attr_decl* next;
|
|
75
|
+
} XsdAttrDecl;
|
|
76
|
+
|
|
77
|
+
/* complexType name -> its attribute declarations (hash-free: a
|
|
78
|
+
* parallel list keyed the same way as complex model roots). */
|
|
79
|
+
typedef struct xsd_type_attrs {
|
|
80
|
+
char* type_name;
|
|
81
|
+
XsdAttrDecl* attrs;
|
|
82
|
+
struct xsd_type_attrs* next;
|
|
83
|
+
} XsdTypeAttrs;
|
|
84
|
+
|
|
40
85
|
#ifdef __cplusplus
|
|
41
86
|
}
|
|
42
87
|
#endif
|
|
88
|
+
|
|
89
|
+
/* ---- slice 4: attribute declarations + instance validation ------- */
|
|
90
|
+
|
|
43
91
|
#endif /* LEPTRIS_XSD_INTERNAL_H */
|
|
@@ -552,3 +552,37 @@ TEST(CliValidate, MissingDtdIsIoError) {
|
|
|
552
552
|
}
|
|
553
553
|
|
|
554
554
|
#endif /* !_WIN32 */
|
|
555
|
+
|
|
556
|
+
// ---- validate --xsd (#1075 slice 5) ---------------------------------
|
|
557
|
+
// The compiled XSD surface rides the same validate command as
|
|
558
|
+
// dtd/rng/schematron. Windows runners: same harness limitation as
|
|
559
|
+
// CliDiff (path + tmp semantics).
|
|
560
|
+
#ifndef _WIN32
|
|
561
|
+
TEST(CliValidateXsd, ValidDocumentExitsZero) {
|
|
562
|
+
write_file("leptris_cli_xsd.tmp",
|
|
563
|
+
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
|
|
564
|
+
"<xs:element name=\"r\" type=\"xs:integer\"/></xs:schema>");
|
|
565
|
+
auto r = run_cli({"validate", "--xsd", "leptris_cli_xsd.tmp",
|
|
566
|
+
"-"}, "<r>7</r>");
|
|
567
|
+
EXPECT_EQ(r.exit_code, 0) << "stderr: " << r.err;
|
|
568
|
+
EXPECT_NE(r.out.find("xsd: valid"), std::string::npos);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
TEST(CliValidateXsd, InvalidDocumentReportsAndExitsNonzero) {
|
|
572
|
+
write_file("leptris_cli_xsd2.tmp",
|
|
573
|
+
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
|
|
574
|
+
"<xs:element name=\"r\" type=\"xs:integer\"/></xs:schema>");
|
|
575
|
+
auto r = run_cli({"validate", "--xsd", "leptris_cli_xsd2.tmp",
|
|
576
|
+
"-"}, "<r>nope</r>");
|
|
577
|
+
EXPECT_NE(r.exit_code, 0);
|
|
578
|
+
EXPECT_NE(r.out.find("xsd: invalid"), std::string::npos);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
TEST(CliValidateXsd, CompileFailureIsReported) {
|
|
582
|
+
write_file("leptris_cli_xsd3.tmp", "<not-a-schema/>");
|
|
583
|
+
auto r = run_cli({"validate", "--xsd", "leptris_cli_xsd3.tmp",
|
|
584
|
+
"-"}, "<r>7</r>");
|
|
585
|
+
EXPECT_NE(r.exit_code, 0);
|
|
586
|
+
EXPECT_NE(r.err.find("XSD compile failed"), std::string::npos);
|
|
587
|
+
}
|
|
588
|
+
#endif
|
|
@@ -264,3 +264,256 @@ TEST(XsdDatatypes, LocalBaseChainValidatesEveryHop) {
|
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
} // namespace
|
|
267
|
+
|
|
268
|
+
// ---- slice 3: content models ---------------------------------------
|
|
269
|
+
namespace {
|
|
270
|
+
|
|
271
|
+
const char* k_cm_schema =
|
|
272
|
+
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""
|
|
273
|
+
" targetNamespace=\"urn:t\">"
|
|
274
|
+
"<xs:complexType name=\"pairT\">"
|
|
275
|
+
"<xs:sequence>"
|
|
276
|
+
"<xs:element name=\"a\"/>"
|
|
277
|
+
"<xs:element name=\"b\"/>"
|
|
278
|
+
"</xs:sequence></xs:complexType>"
|
|
279
|
+
"<xs:element name=\"pair\" type=\"pairT\"/>"
|
|
280
|
+
|
|
281
|
+
"<xs:complexType name=\"pickT\">"
|
|
282
|
+
"<xs:choice>"
|
|
283
|
+
"<xs:element name=\"x\"/>"
|
|
284
|
+
"<xs:element name=\"y\"/>"
|
|
285
|
+
"</xs:choice></xs:complexType>"
|
|
286
|
+
"<xs:element name=\"pick\" type=\"pickT\"/>"
|
|
287
|
+
|
|
288
|
+
"<xs:complexType name=\"twoToThreeT\">"
|
|
289
|
+
"<xs:sequence>"
|
|
290
|
+
"<xs:element name=\"a\" minOccurs=\"2\" maxOccurs=\"3\"/>"
|
|
291
|
+
"</xs:sequence></xs:complexType>"
|
|
292
|
+
"<xs:element name=\"twoToThree\" type=\"twoToThreeT\"/>"
|
|
293
|
+
|
|
294
|
+
"<xs:complexType name=\"listT\">"
|
|
295
|
+
"<xs:sequence>"
|
|
296
|
+
"<xs:element name=\"item\" maxOccurs=\"unbounded\"/>"
|
|
297
|
+
"</xs:sequence></xs:complexType>"
|
|
298
|
+
"<xs:element name=\"list\" type=\"listT\"/>"
|
|
299
|
+
|
|
300
|
+
"<xs:complexType name=\"looseT\">"
|
|
301
|
+
"<xs:sequence>"
|
|
302
|
+
"<xs:any namespace=\"##other\" processContents=\"skip\"/>"
|
|
303
|
+
"</xs:sequence></xs:complexType>"
|
|
304
|
+
"<xs:element name=\"loose\" type=\"looseT\"/>"
|
|
305
|
+
|
|
306
|
+
"<xs:complexType name=\"nestedT\">"
|
|
307
|
+
"<xs:sequence>"
|
|
308
|
+
"<xs:choice>"
|
|
309
|
+
"<xs:element name=\"x\"/>"
|
|
310
|
+
"<xs:element name=\"y\"/>"
|
|
311
|
+
"</xs:choice>"
|
|
312
|
+
"<xs:element name=\"c\"/>"
|
|
313
|
+
"</xs:sequence></xs:complexType>"
|
|
314
|
+
"<xs:element name=\"nested\" type=\"nestedT\"/>"
|
|
315
|
+
|
|
316
|
+
"<xs:element name=\"text\" type=\"xs:string\"/>"
|
|
317
|
+
"</xs:schema>";
|
|
318
|
+
|
|
319
|
+
LeptrisXsdSchema compile_cm() {
|
|
320
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
321
|
+
LeptrisXsdSchema s =
|
|
322
|
+
leptris_xsd_compile(k_cm_schema, strlen(k_cm_schema), &st);
|
|
323
|
+
EXPECT_EQ(st, LEPTRIS_OK);
|
|
324
|
+
return s;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
TEST(XsdContent, SequenceInOrder) {
|
|
328
|
+
LeptrisXsdSchema s = compile_cm();
|
|
329
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0);
|
|
330
|
+
const char* ab[] = {"a", "b"};
|
|
331
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "pair", ab, NULL, 2), 1);
|
|
332
|
+
const char* ba[] = {"b", "a"};
|
|
333
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "pair", ba, NULL, 2), 0);
|
|
334
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "pair", ab, NULL, 1), 0);
|
|
335
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "pair", NULL, NULL, 0), 0);
|
|
336
|
+
leptris_xsd_free(s);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
TEST(XsdContent, ChoicePicksExactlyOne) {
|
|
340
|
+
LeptrisXsdSchema s = compile_cm();
|
|
341
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0);
|
|
342
|
+
const char* x[] = {"x"};
|
|
343
|
+
const char* y[] = {"y"};
|
|
344
|
+
const char* xy[] = {"x", "y"};
|
|
345
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "pick", x, NULL, 1), 1);
|
|
346
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "pick", y, NULL, 1), 1);
|
|
347
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "pick", xy, NULL, 2), 0);
|
|
348
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "pick", NULL, NULL, 0), 0);
|
|
349
|
+
leptris_xsd_free(s);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
TEST(XsdContent, OccurrenceBoundsHold) {
|
|
353
|
+
LeptrisXsdSchema s = compile_cm();
|
|
354
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0);
|
|
355
|
+
const char* a1[] = {"a"};
|
|
356
|
+
const char* a2[] = {"a", "a"};
|
|
357
|
+
const char* a3[] = {"a", "a", "a"};
|
|
358
|
+
const char* a4[] = {"a", "a", "a", "a"};
|
|
359
|
+
SCOPED_TRACE("a1");
|
|
360
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "twoToThree", a1, NULL, 1), 0);
|
|
361
|
+
SCOPED_TRACE("a2");
|
|
362
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "twoToThree", a2, NULL, 2), 1);
|
|
363
|
+
SCOPED_TRACE("a3");
|
|
364
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "twoToThree", a3, NULL, 3), 1);
|
|
365
|
+
SCOPED_TRACE("a4");
|
|
366
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "twoToThree", a4, NULL, 4), 0);
|
|
367
|
+
leptris_xsd_free(s);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
TEST(XsdContent, UnboundedRepeats) {
|
|
371
|
+
LeptrisXsdSchema s = compile_cm();
|
|
372
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0);
|
|
373
|
+
const char* i3[] = {"item", "item", "item"};
|
|
374
|
+
const char* i30[30];
|
|
375
|
+
for (int i = 0; i < 30; i++) i30[i] = "item";
|
|
376
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "list", NULL, NULL, 0), 0);
|
|
377
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "list", i3, NULL, 3), 1);
|
|
378
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "list", i30, NULL, 30), 1);
|
|
379
|
+
leptris_xsd_free(s);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
TEST(XsdContent, WildcardNamespaceFilter) {
|
|
383
|
+
LeptrisXsdSchema s = compile_cm();
|
|
384
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0);
|
|
385
|
+
/* ##other: anything qualified OUTSIDE urn:t */
|
|
386
|
+
const char* w[] = {"widget"};
|
|
387
|
+
const char* tns[] = {"urn:t"};
|
|
388
|
+
const char* other[] = {"urn:elsewhere"};
|
|
389
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "loose", w, other, 1), 1);
|
|
390
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "loose", w, tns, 1), 0);
|
|
391
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "loose", w, NULL, 1), 0);
|
|
392
|
+
leptris_xsd_free(s);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
TEST(XsdContent, NestedGroupsCompose) {
|
|
396
|
+
LeptrisXsdSchema s = compile_cm();
|
|
397
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0);
|
|
398
|
+
const char* xc[] = {"x", "c"};
|
|
399
|
+
const char* yc[] = {"y", "c"};
|
|
400
|
+
const char* cc[] = {"c", "c"};
|
|
401
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "nested", xc, NULL, 2), 1);
|
|
402
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "nested", yc, NULL, 2), 1);
|
|
403
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "nested", cc, NULL, 2), 0);
|
|
404
|
+
leptris_xsd_free(s);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
TEST(XsdContent, SimpleTypedElementTakesNoChildren) {
|
|
408
|
+
LeptrisXsdSchema s = compile_cm();
|
|
409
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0);
|
|
410
|
+
const char* x[] = {"x"};
|
|
411
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "text", NULL, NULL, 0), 1);
|
|
412
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "text", x, NULL, 1), 0);
|
|
413
|
+
EXPECT_EQ(leptris_xsd_content_valid(s, "noSuchElement", x, NULL, 1),
|
|
414
|
+
-1);
|
|
415
|
+
leptris_xsd_free(s);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
} // namespace
|
|
419
|
+
|
|
420
|
+
// ---- slice 4: instance validation ----------------------------------
|
|
421
|
+
namespace {
|
|
422
|
+
|
|
423
|
+
const char* k_v_schema =
|
|
424
|
+
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
|
|
425
|
+
"<xs:complexType name=\"rowT\">"
|
|
426
|
+
"<xs:sequence>"
|
|
427
|
+
"<xs:element name=\"id\" type=\"xs:integer\"/>"
|
|
428
|
+
"<xs:element name=\"name\" type=\"xs:string\"/>"
|
|
429
|
+
"</xs:sequence>"
|
|
430
|
+
"<xs:attribute name=\"status\" type=\"xs:string\"/>"
|
|
431
|
+
"<xs:attribute name=\"version\" type=\"xs:integer\""
|
|
432
|
+
" use=\"required\"/>"
|
|
433
|
+
"</xs:complexType>"
|
|
434
|
+
"<xs:element name=\"rows\" type=\"rowT\"/>"
|
|
435
|
+
"<xs:element name=\"count\" type=\"xs:positiveInteger\"/>"
|
|
436
|
+
"</xs:schema>";
|
|
437
|
+
|
|
438
|
+
int validate_doc(const char* schema, const char* xml) {
|
|
439
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
440
|
+
LeptrisXsdSchema s =
|
|
441
|
+
leptris_xsd_compile(schema, strlen(schema), &st);
|
|
442
|
+
if (!s) return -2;
|
|
443
|
+
LeptrisDocument d = leptris_parse_string(xml, strlen(xml), &st);
|
|
444
|
+
if (!d) {
|
|
445
|
+
leptris_xsd_free(s);
|
|
446
|
+
return -3;
|
|
447
|
+
}
|
|
448
|
+
int r = leptris_xsd_validate(s, d);
|
|
449
|
+
leptris_document_free(d);
|
|
450
|
+
leptris_xsd_free(s);
|
|
451
|
+
return r;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
TEST(XsdValidate, ValidDocumentPasses) {
|
|
455
|
+
EXPECT_EQ(validate_doc(k_v_schema,
|
|
456
|
+
"<rows version=\"2\" status=\"ok\">"
|
|
457
|
+
"<id>7</id><name>abc</name></rows>"), 1);
|
|
458
|
+
EXPECT_EQ(validate_doc(k_v_schema, "<count>3</count>"), 1);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
TEST(XsdValidate, ContentModelViolationReports) {
|
|
462
|
+
EXPECT_EQ(validate_doc(k_v_schema,
|
|
463
|
+
"<rows version=\"1\">"
|
|
464
|
+
"<name>abc</name><id>7</id></rows>"), 0);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
TEST(XsdValidate, RequiredAttributeAbsentReports) {
|
|
468
|
+
int r = validate_doc(k_v_schema, "<rows><id>7</id><name>a</name></rows>");
|
|
469
|
+
EXPECT_EQ(r, 0);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
TEST(XsdValidate, AttributeTypeViolationReports) {
|
|
473
|
+
EXPECT_EQ(validate_doc(k_v_schema,
|
|
474
|
+
"<rows version=\"x\"><id>7</id>"
|
|
475
|
+
"<name>a</name></rows>"), 0);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
TEST(XsdValidate, ElementTextTypeViolationReports) {
|
|
479
|
+
EXPECT_EQ(validate_doc(k_v_schema, "<count>-2</count>"), 0);
|
|
480
|
+
EXPECT_EQ(validate_doc(k_v_schema, "<count>0</count>"), 0);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
TEST(XsdValidate, ChildElementTypeViolationReports) {
|
|
484
|
+
EXPECT_EQ(validate_doc(k_v_schema,
|
|
485
|
+
"<rows version=\"1\">"
|
|
486
|
+
"<id>nan</id><name>a</name></rows>"), 0);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
TEST(XsdValidate, ErrorsEnumerate) {
|
|
490
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
491
|
+
LeptrisXsdSchema s =
|
|
492
|
+
leptris_xsd_compile(k_v_schema, strlen(k_v_schema), &st);
|
|
493
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0);
|
|
494
|
+
const char* bad = "<rows><id>nan</id><name>a</name></rows>";
|
|
495
|
+
LeptrisDocument d = leptris_parse_string(bad, strlen(bad), &st);
|
|
496
|
+
ASSERT_NE(d, nullptr);
|
|
497
|
+
int r = leptris_xsd_validate(s, d);
|
|
498
|
+
EXPECT_EQ(r, 0);
|
|
499
|
+
EXPECT_GE(leptris_xsd_error_count(s), 1u);
|
|
500
|
+
const char* first = leptris_xsd_error_at(s, 0);
|
|
501
|
+
EXPECT_NE(first, nullptr);
|
|
502
|
+
EXPECT_EQ(leptris_xsd_error_at(s, 99), nullptr);
|
|
503
|
+
leptris_document_free(d);
|
|
504
|
+
leptris_xsd_free(s);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
TEST(XsdValidate, NullTolerant) {
|
|
508
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
509
|
+
LeptrisXsdSchema s =
|
|
510
|
+
leptris_xsd_compile(k_v_schema, strlen(k_v_schema), &st);
|
|
511
|
+
ASSERT_NE(s, (LeptrisXsdSchema)0);
|
|
512
|
+
EXPECT_EQ(leptris_xsd_validate(NULL, NULL), -1);
|
|
513
|
+
EXPECT_EQ(leptris_xsd_validate(s, NULL), -1);
|
|
514
|
+
EXPECT_EQ(leptris_xsd_error_count(NULL), 0u);
|
|
515
|
+
EXPECT_EQ(leptris_xsd_error_at(NULL, 0), nullptr);
|
|
516
|
+
leptris_xsd_free(s);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
} // namespace
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
|
|
3
3
|
"name": "leptris",
|
|
4
|
-
"version": "1.9.
|
|
4
|
+
"version": "1.9.322",
|
|
5
5
|
"description": "High-performance XML parser and XPath 1.0 engine in C (libleptris)",
|
|
6
6
|
"homepage": "https://github.com/leptris/leptris",
|
|
7
7
|
"license": "MIT",
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: leptris
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.9.
|
|
4
|
+
version: 1.9.322.0
|
|
5
5
|
platform: arm-linux
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -697,7 +697,9 @@ files:
|
|
|
697
697
|
- vendor-src/libleptris/src/leptris/xpath/xpath_variables.h
|
|
698
698
|
- vendor-src/libleptris/src/leptris/xquery/xquery.c
|
|
699
699
|
- vendor-src/libleptris/src/leptris/xsd/compile.c
|
|
700
|
+
- vendor-src/libleptris/src/leptris/xsd/content_model.c
|
|
700
701
|
- vendor-src/libleptris/src/leptris/xsd/datatypes.c
|
|
702
|
+
- vendor-src/libleptris/src/leptris/xsd/validate.c
|
|
701
703
|
- vendor-src/libleptris/src/leptris/xsd/xsd_internal.h
|
|
702
704
|
- vendor-src/libleptris/src/leptris/xslt/xslt_exec.c
|
|
703
705
|
- vendor-src/libleptris/src/leptris/xslt/xslt_functions.c
|