leptris 1.9.319.0-arm-linux → 1.9.321.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 +35 -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 +45 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- 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/descriptor/plan.c +35 -3
- 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/abi/test_descriptor.cpp +168 -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 */
|
|
@@ -1963,3 +1963,171 @@ TEST(Plan1563, PlainAttrRowAgreesNestedVsRoot) {
|
|
|
1963
1963
|
leptris_plan_free(root_plan);
|
|
1964
1964
|
leptris_plan_free(nested_plan);
|
|
1965
1965
|
}
|
|
1966
|
+
|
|
1967
|
+
// ---- #1585: child-row exact-URI ns_uri retention -------------------
|
|
1968
|
+
// The build copied child ns_prefix but left ns_uri pointing at the
|
|
1969
|
+
// CALLER's buffer — once the binding's build anchors are GC'd the
|
|
1970
|
+
// row dangles and silently stops matching. Retention is observable
|
|
1971
|
+
// without a GC: trash the caller's buffer after build; the row
|
|
1972
|
+
// must still bind.
|
|
1973
|
+
TEST(Plan1585, ChildRowNsUriIsRetained) {
|
|
1974
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
1975
|
+
char ns_uri_buf[64];
|
|
1976
|
+
strcpy(ns_uri_buf, "http://purl.org/dc/elements/1.1/");
|
|
1977
|
+
|
|
1978
|
+
leptris_child_plan kids[2] = {};
|
|
1979
|
+
kids[0].wire_name = "c";
|
|
1980
|
+
kids[0].kind = LEPTRIS_PLAN_KIND_SCALAR;
|
|
1981
|
+
kids[0].type_tag = 1;
|
|
1982
|
+
kids[0].child_plan_index = -1;
|
|
1983
|
+
kids[0].ns_form = LEPTRIS_PLAN_NS_EXACT;
|
|
1984
|
+
kids[0].ns_uri = ns_uri_buf;
|
|
1985
|
+
kids[0].ns_prefix = "d";
|
|
1986
|
+
kids[1].wire_name = "p";
|
|
1987
|
+
kids[1].kind = LEPTRIS_PLAN_KIND_SCALAR;
|
|
1988
|
+
kids[1].type_tag = 2;
|
|
1989
|
+
kids[1].child_plan_index = -1;
|
|
1990
|
+
leptris_element_plan plans[1] = {};
|
|
1991
|
+
plans[0].element_name = "r";
|
|
1992
|
+
plans[0].ns_form = LEPTRIS_PLAN_NS_ANY;
|
|
1993
|
+
plans[0].child_count = 2;
|
|
1994
|
+
plans[0].child_plans = kids;
|
|
1995
|
+
leptris_plan_spec spec = {};
|
|
1996
|
+
spec.abi_version = leptris_plan_abi_version();
|
|
1997
|
+
spec.plan_count = 1;
|
|
1998
|
+
spec.plans = plans;
|
|
1999
|
+
LeptrisPlan plan = leptris_plan_build(&spec, &st);
|
|
2000
|
+
ASSERT_NE(plan, nullptr);
|
|
2001
|
+
|
|
2002
|
+
/* Simulate the GC reclaiming the build anchor: the spec buffer
|
|
2003
|
+
* is now garbage. */
|
|
2004
|
+
memset(ns_uri_buf, 'X', sizeof(ns_uri_buf) - 1);
|
|
2005
|
+
|
|
2006
|
+
LeptrisDocument doc = parse(
|
|
2007
|
+
"<r xmlns:d=\"http://purl.org/dc/elements/1.1/\">"
|
|
2008
|
+
"<d:c>x</d:c><p>y</p></r>");
|
|
2009
|
+
ASSERT_NE(doc, nullptr);
|
|
2010
|
+
LeptrisPlanResult r =
|
|
2011
|
+
leptris_plan_walk(doc, leptris_document_root(doc), plan, &st);
|
|
2012
|
+
ASSERT_NE(r, nullptr);
|
|
2013
|
+
ASSERT_EQ(leptris_plan_value_count(r), 2u);
|
|
2014
|
+
EXPECT_STREQ(leptris_plan_value_string(leptris_plan_value_at(r, 0)),
|
|
2015
|
+
"x")
|
|
2016
|
+
<< "exact-URI child row lost its ns_uri";
|
|
2017
|
+
EXPECT_STREQ(leptris_plan_value_string(leptris_plan_value_at(r, 1)),
|
|
2018
|
+
"y");
|
|
2019
|
+
leptris_plan_result_free(r);
|
|
2020
|
+
leptris_plan_free(plan);
|
|
2021
|
+
leptris_document_free(doc);
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
// ---- #1586: plain attribute rows match any qualification -----------
|
|
2025
|
+
// The plan-path mirror of #758 (exact wire spelling first, then any
|
|
2026
|
+
// qualification by local name) — a plain attr row must bind w:name
|
|
2027
|
+
// the same way the interpretive path does, at top level and nested.
|
|
2028
|
+
TEST(Plan1586, PlainAttrRowLenientSpelling) {
|
|
2029
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
2030
|
+
const char* xml = "<r xmlns:w=\"http://w/1\" w:top=\"T\"/>";
|
|
2031
|
+
|
|
2032
|
+
leptris_attr_plan attrs[1] = {};
|
|
2033
|
+
attrs[0].wire_name = "top";
|
|
2034
|
+
attrs[0].kind = LEPTRIS_PLAN_KIND_SCALAR;
|
|
2035
|
+
attrs[0].type_tag = 1;
|
|
2036
|
+
leptris_element_plan plans[1] = {};
|
|
2037
|
+
plans[0].element_name = "r";
|
|
2038
|
+
plans[0].attribute_count = 1;
|
|
2039
|
+
plans[0].attribute_plans = attrs;
|
|
2040
|
+
plans[0].flags = LEPTRIS_PLAN_FLAG_NS_LENIENT;
|
|
2041
|
+
leptris_plan_spec spec = {};
|
|
2042
|
+
spec.abi_version = leptris_plan_abi_version();
|
|
2043
|
+
spec.plan_count = 1;
|
|
2044
|
+
spec.plans = plans;
|
|
2045
|
+
LeptrisPlan plan = leptris_plan_build(&spec, &st);
|
|
2046
|
+
ASSERT_NE(plan, nullptr);
|
|
2047
|
+
|
|
2048
|
+
LeptrisDocument doc = parse(xml);
|
|
2049
|
+
ASSERT_NE(doc, nullptr);
|
|
2050
|
+
LeptrisPlanResult r =
|
|
2051
|
+
leptris_plan_walk(doc, leptris_document_root(doc), plan, &st);
|
|
2052
|
+
ASSERT_NE(r, nullptr);
|
|
2053
|
+
EXPECT_STREQ(leptris_plan_value_attribute(r, "top"), "T");
|
|
2054
|
+
leptris_plan_result_free(r);
|
|
2055
|
+
leptris_document_free(doc);
|
|
2056
|
+
leptris_plan_free(plan);
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
TEST(Plan1586, PlainAttrRowLenientUnderNestedRow) {
|
|
2060
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
2061
|
+
const char* xml = "<r xmlns:w=\"http://w/1\"><w:c w:n=\"N\"/></r>";
|
|
2062
|
+
|
|
2063
|
+
leptris_attr_plan c_attrs[1] = {};
|
|
2064
|
+
c_attrs[0].wire_name = "n";
|
|
2065
|
+
c_attrs[0].kind = LEPTRIS_PLAN_KIND_SCALAR;
|
|
2066
|
+
c_attrs[0].type_tag = 1;
|
|
2067
|
+
leptris_child_plan c_row = {};
|
|
2068
|
+
c_row.wire_name = "c";
|
|
2069
|
+
c_row.kind = LEPTRIS_PLAN_KIND_NESTED;
|
|
2070
|
+
c_row.child_plan_index = 1;
|
|
2071
|
+
c_row.ns_form = LEPTRIS_PLAN_NS_ANY;
|
|
2072
|
+
leptris_element_plan plans[2] = {};
|
|
2073
|
+
plans[0].element_name = "r";
|
|
2074
|
+
plans[0].child_count = 1;
|
|
2075
|
+
plans[0].child_plans = &c_row;
|
|
2076
|
+
plans[1].element_name = "c";
|
|
2077
|
+
plans[1].attribute_count = 1;
|
|
2078
|
+
plans[1].attribute_plans = c_attrs;
|
|
2079
|
+
plans[1].flags = LEPTRIS_PLAN_FLAG_NS_LENIENT;
|
|
2080
|
+
leptris_plan_spec spec = {};
|
|
2081
|
+
spec.abi_version = leptris_plan_abi_version();
|
|
2082
|
+
spec.plan_count = 2;
|
|
2083
|
+
spec.plans = plans;
|
|
2084
|
+
LeptrisPlan plan = leptris_plan_build(&spec, &st);
|
|
2085
|
+
ASSERT_NE(plan, nullptr);
|
|
2086
|
+
|
|
2087
|
+
LeptrisDocument doc = parse(xml);
|
|
2088
|
+
ASSERT_NE(doc, nullptr);
|
|
2089
|
+
LeptrisPlanResult r =
|
|
2090
|
+
leptris_plan_walk(doc, leptris_document_root(doc), plan, &st);
|
|
2091
|
+
ASSERT_NE(r, nullptr);
|
|
2092
|
+
ASSERT_EQ(leptris_plan_value_count(r), 1u);
|
|
2093
|
+
LeptrisPlanResult child = leptris_plan_value_at(r, 0);
|
|
2094
|
+
ASSERT_NE(child, nullptr);
|
|
2095
|
+
EXPECT_STREQ(leptris_plan_value_attribute(child, "n"), "N");
|
|
2096
|
+
leptris_plan_result_free(r);
|
|
2097
|
+
leptris_document_free(doc);
|
|
2098
|
+
leptris_plan_free(plan);
|
|
2099
|
+
}
|
|
2100
|
+
|
|
2101
|
+
TEST(Plan1586, ExactUriRowStillWinsAndUnqualifiedStillBinds) {
|
|
2102
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
2103
|
+
/* exact-URI row keeps its #1486 semantics; unqualified wire
|
|
2104
|
+
* attr binds a plain row by the literal spelling. */
|
|
2105
|
+
const char* xml = "<r xmlns:w=\"http://w/1\" w:top=\"T\" top=\"U\"/>";
|
|
2106
|
+
leptris_attr_plan exact[1] = {};
|
|
2107
|
+
exact[0].wire_name = "top";
|
|
2108
|
+
exact[0].kind = LEPTRIS_PLAN_KIND_SCALAR;
|
|
2109
|
+
exact[0].type_tag = 1;
|
|
2110
|
+
exact[0].ns_form = LEPTRIS_PLAN_NS_EXACT;
|
|
2111
|
+
exact[0].ns_uri = "http://w/1";
|
|
2112
|
+
leptris_element_plan plans[1] = {};
|
|
2113
|
+
plans[0].element_name = "r";
|
|
2114
|
+
plans[0].attribute_count = 1;
|
|
2115
|
+
plans[0].attribute_plans = exact;
|
|
2116
|
+
leptris_plan_spec spec = {};
|
|
2117
|
+
spec.abi_version = leptris_plan_abi_version();
|
|
2118
|
+
spec.plan_count = 1;
|
|
2119
|
+
spec.plans = plans;
|
|
2120
|
+
LeptrisPlan plan = leptris_plan_build(&spec, &st);
|
|
2121
|
+
ASSERT_NE(plan, nullptr);
|
|
2122
|
+
LeptrisDocument doc = parse(xml);
|
|
2123
|
+
ASSERT_NE(doc, nullptr);
|
|
2124
|
+
LeptrisPlanResult r =
|
|
2125
|
+
leptris_plan_walk(doc, leptris_document_root(doc), plan, &st);
|
|
2126
|
+
ASSERT_NE(r, nullptr);
|
|
2127
|
+
/* The qualified spelling carries "T"; the exact row must take
|
|
2128
|
+
* it, not the unqualified "U". */
|
|
2129
|
+
EXPECT_STREQ(leptris_plan_value_attribute(r, "top"), "T");
|
|
2130
|
+
leptris_plan_result_free(r);
|
|
2131
|
+
leptris_document_free(doc);
|
|
2132
|
+
leptris_plan_free(plan);
|
|
2133
|
+
}
|