leptris 1.9.404.0 → 1.9.406.0

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/ext/leptris/native/native.c +60 -0
  4. data/lib/leptris/vendor/aarch64-linux/libleptris.so +0 -0
  5. data/lib/leptris/vendor/aarch64-linux-musl/libleptris.so +0 -0
  6. data/lib/leptris/vendor/arm-linux/libleptris.so +0 -0
  7. data/lib/leptris/vendor/arm-linux-musl/libleptris.so +0 -0
  8. data/lib/leptris/vendor/arm64-darwin/libleptris.dylib +0 -0
  9. data/lib/leptris/vendor/ppc64le-linux/libleptris.so +0 -0
  10. data/lib/leptris/vendor/s390x-linux-musl/libleptris.so +0 -0
  11. data/lib/leptris/vendor/x86_64-darwin/libleptris.dylib +0 -0
  12. data/lib/leptris/vendor/x86_64-linux/libleptris.so +0 -0
  13. data/lib/leptris/vendor/x86_64-linux-musl/libleptris.so +0 -0
  14. data/lib/leptris/version.rb +1 -1
  15. data/lib/leptris/xml/descriptor.rb +3 -0
  16. data/lib/leptris/xml/ffi.rb +2 -0
  17. data/vendor-src/README.md +1 -1
  18. data/vendor-src/libleptris/CHANGELOG.md +51 -0
  19. data/vendor-src/libleptris/CMakeLists.txt +1 -1
  20. data/vendor-src/libleptris/src/include/leptris/descriptor.h +9 -1
  21. data/vendor-src/libleptris/src/leptris/descriptor/plan.c +26 -0
  22. data/vendor-src/libleptris/src/leptris/xsd/compile.c +180 -13
  23. data/vendor-src/libleptris/src/leptris/xsd/validate.c +102 -17
  24. data/vendor-src/libleptris/src/leptris/xsd/xsd_internal.h +5 -0
  25. data/vendor-src/libleptris/test/CMakeLists.txt +3 -0
  26. data/vendor-src/libleptris/test/abi/test_descriptor.cpp +39 -0
  27. data/vendor-src/libleptris/test/xsd/libxml2-cases/i1957/instance.xml +2 -0
  28. data/vendor-src/libleptris/test/xsd/libxml2-cases/i1957/schema.xsd +16 -0
  29. data/vendor-src/libleptris/test/xsd/libxml2-cases/i1958/schF1.xml +14 -0
  30. data/vendor-src/libleptris/test/xsd/libxml2-cases/i1958/schF1_a.xsd +28 -0
  31. data/vendor-src/libleptris/test/xsd/libxml2-cases/i1958/schF1_b.xsd +14 -0
  32. data/vendor-src/libleptris/test/xsd/libxml2-cases/i1958/schP2.xml +2 -0
  33. data/vendor-src/libleptris/test/xsd/libxml2-cases/i1958/schP2_a.xsd +27 -0
  34. data/vendor-src/libleptris/test/xsd/libxml2-cases/i1958/schP2_b.xsd +12 -0
  35. data/vendor-src/libleptris/test/xsd/libxml2-cases/rs35_w3c/addB104.xml +6 -0
  36. data/vendor-src/libleptris/test/xsd/libxml2-cases/rs35_w3c/addB104.xsd +19 -0
  37. data/vendor-src/libleptris/test/xsd/libxml2-cases/rs35_w3c/attO006.xml +4 -0
  38. data/vendor-src/libleptris/test/xsd/libxml2-cases/rs35_w3c/attO006.xsd +15 -0
  39. data/vendor-src/libleptris/test/xsd/test_i1957_1958.cpp +90 -0
  40. data/vendor-src/libleptris/test/xsd/test_rs35_regression.cpp +11 -0
  41. data/vendor-src/libleptris/vcpkg.json +1 -1
  42. metadata +15 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66ef03e53d9af3c266aaad33fad1be0b38b93d68dbc5225632ab93a7010366f6
4
- data.tar.gz: 2dca1c73bc448cae8a4568122248509924569bf2c2ba22f4220514034838521b
3
+ metadata.gz: b4a0df0f71b165f64f4cd58454df8b8d8574c86e4f8ad3d8a878234e4f330927
4
+ data.tar.gz: ab281397839b832e511d93b1763c18dc193bbbdeb7a508eb5b7b17e18b79c026
5
5
  SHA512:
6
- metadata.gz: 733faccb13e2cf6dbfc07a95250eaae19ad1d029e94aa557d854ce67a71c50a53d6b87de84e2c48cd58cde561bbdb7b625dc177ac18e5588ad7af0e75b86235f
7
- data.tar.gz: 05bf2d8a17412435b2fba4d2d62fc451e80669b1eb3246061326266bf4568cd1e351ca07d116cad8813bc7c1204e1331bfaac686cac0810efd232034f966184d
6
+ metadata.gz: ae7d9e574aa736a7959ad9fa1c7d9a48771bcb98760b6c81c1778d845af2ee96f5cf7221d9466514091fe117ca865257d7057b8ed4b4f2e4caa526e700008521
7
+ data.tar.gz: 76f33da5b1a885660b85a0b1e6c95226a3013ce234dda403951c2f006f0f1d2053bd81cd8b91a2cc97c62ee6415d1586b39251c018b46a6f4e7960a1456957d4
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ RSpec::Core::RakeTask.new(:spec)
8
8
  # Pin for `rake compile` and the platform-gem builds. Keep in lockstep
9
9
  # with .github/workflows/build.yml (which calls `rake compile`) and the
10
10
  # CHANGELOG when libleptris releases.
11
- LIBLEPTRIS_VERSION = "1.9.404"
11
+ LIBLEPTRIS_VERSION = "1.9.406"
12
12
  # Vendored alongside libleptris for fn:normalize-unicode (TODO
13
13
  # .restructure/20): built per platform with a RELOCATABLE @rpath
14
14
  # install name, loaded by ffi.rb before libleptris so the
@@ -2782,6 +2782,64 @@ static VALUE nf_walk_columnar(VALUE self, VALUE root)
2782
2782
  return rb_ary_new3(3, names, handles, depths);
2783
2783
  }
2784
2784
 
2785
+ /* ---- Raw-address columnar walk (leptris-ruby#587) ----------------
2786
+ * The identity-free read lane: the preorder/depths contract of
2787
+ * walk_columnar (#527), but the handles lane carries RAW NODE
2788
+ * ADDRESSES as Integers instead of minted NativeNodes — addresses
2789
+ * are immediates in CRuby, so a whole-subtree read walk allocates
2790
+ * nothing per node beyond the three arrays, mints nothing, and
2791
+ * writes nothing into the per-document identity cache. Names are
2792
+ * interned fstrings exactly as walk_columnar produces them.
2793
+ *
2794
+ * Read-only consumers resolve everything through the address-keyed
2795
+ * faces (fast_name, fast_element_text, attribute_pairs, ...). A
2796
+ * consumer that later needs a mutable, identity-backed handle
2797
+ * mints it through the normal wrap path — the write lane is
2798
+ * unchanged. This is the shadow-binding read half: Ruby objects
2799
+ * exist only where the consumer holds state, never per visited
2800
+ * node. */
2801
+ static void walk_addresses_impl(void *node, int depth, VALUE names,
2802
+ VALUE addrs, VALUE depths)
2803
+ {
2804
+ int kind = f_node_type(node);
2805
+ void *c;
2806
+
2807
+ if (kind == WS_NODE_ELEMENT) {
2808
+ const char *name = f_elem_name(node);
2809
+ rb_ary_push(names, name
2810
+ ? rb_enc_interned_str(name, strlen(name),
2811
+ rb_utf8_encoding())
2812
+ : Qnil);
2813
+ rb_ary_push(addrs, ULL2NUM((uint64_t)(uintptr_t)node));
2814
+ rb_ary_push(depths, INT2NUM(depth));
2815
+ for (c = f_first_child(node); c; c = f_next_sibling(c)) {
2816
+ walk_addresses_impl(c, depth + 1, names, addrs, depths);
2817
+ }
2818
+ } else if (kind == WS_NODE_TEXT || kind == WS_NODE_COMMENT ||
2819
+ kind == WS_NODE_CDATA || kind == WS_NODE_PI) {
2820
+ rb_ary_push(names, Qnil);
2821
+ rb_ary_push(addrs, ULL2NUM((uint64_t)(uintptr_t)node));
2822
+ rb_ary_push(depths, INT2NUM(depth));
2823
+ } else if (kind == WS_NODE_DOCTYPE || kind == 9 /* DOCUMENT */) {
2824
+ for (c = f_first_child(node); c; c = f_next_sibling(c)) {
2825
+ walk_addresses_impl(c, depth, names, addrs, depths);
2826
+ }
2827
+ }
2828
+ }
2829
+
2830
+ static VALUE nf_walk_addresses(VALUE self, VALUE root)
2831
+ {
2832
+ struct native_node *n;
2833
+ VALUE names, addrs, depths;
2834
+ (void)self;
2835
+ TypedData_Get_Struct(root, struct native_node, &nn_type, n);
2836
+ names = rb_ary_new();
2837
+ addrs = rb_ary_new();
2838
+ depths = rb_ary_new();
2839
+ walk_addresses_impl(n->ptr, 0, names, addrs, depths);
2840
+ return rb_ary_new3(3, names, addrs, depths);
2841
+ }
2842
+
2785
2843
  /* ---- Struct plan executor (moxml "miles faster" round) ------------
2786
2844
  * The consumer's shape compiles to spec: name (interned String) ->
2787
2845
  * [Struct class, attrs Hash (name -> slot Symbol), text slot Symbol
@@ -4200,6 +4258,8 @@ static void leptris_native_setup(void)
4200
4258
  nf_snapshot_rows, 2);
4201
4259
  rb_define_module_function(m_native, "walk_columnar",
4202
4260
  nf_walk_columnar, 1);
4261
+ rb_define_module_function(m_native, "walk_addresses",
4262
+ nf_walk_addresses, 1);
4203
4263
  rb_define_module_function(m_native, "attribute_pairs",
4204
4264
  nf_attribute_pairs, 2);
4205
4265
  rb_define_module_function(m_native, "plan_structs",
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leptris
4
- VERSION = "1.9.404.0"
4
+ VERSION = "1.9.406.0"
5
5
  end
@@ -388,6 +388,9 @@ class Leptris::XML::Descriptor
388
388
  element: Leptris::XML::FFI::PLAN_OP_ELEMENT,
389
389
  attr: Leptris::XML::FFI::PLAN_OP_ATTR,
390
390
  end: Leptris::XML::FFI::PLAN_OP_END,
391
+ # leptris#1941: value carries a host-serialized fragment; the
392
+ # engine stores it as a VALUE_RAW and emits it verbatim.
393
+ raw: Leptris::XML::FFI::PLAN_OP_RAW,
391
394
  }.freeze
392
395
  private_constant :ROW_OP_KINDS
393
396
 
@@ -440,6 +440,8 @@ module Leptris
440
440
  PLAN_OP_ELEMENT = 1
441
441
  PLAN_OP_ATTR = 2
442
442
  PLAN_OP_END = 3
443
+ # leptris#1941: splice a host-serialized fragment verbatim.
444
+ PLAN_OP_RAW = 4
443
445
  attach_function :leptris_plan_result_build,
444
446
  [:leptris_plan, :pointer, :size_t, :pointer], :leptris_plan_result
445
447
  # libleptris 1.9.387: the packed-blob lane of the same face
data/vendor-src/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Sources vendored in this gem (recompile rights; the ruby
2
2
  variant builds them at install via extconf.rb):
3
3
 
4
- - libleptris v1.9.404
4
+ - libleptris v1.9.406
5
5
  - utf8proc v2.11.0
6
6
 
7
7
  Rebuild by hand:
@@ -1,5 +1,56 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.9.406] - 2026-11-03
4
+
5
+ ### Added
6
+
7
+ - descriptor: `LEPTRIS_PLAN_OP_RAW` (op kind 4) — the serializer's escape hatch. Host-side code serializes a fragment (typically a lutaml-model child_deferred subtree) and the plan emits it verbatim as a `VALUE_RAW` row, so ordered/deferred/mixed layouts no longer fall back to per-node `create_element` minting. Closes the engine half of the #1941 wrapper-free serialize face.
8
+ - descriptor: emission rows are stamped with their plan row identity (`row_index` + `container_plan`), which the serializer's CONTENT check requires to address the correct `child_plans` slot.
9
+
10
+ ### Fixed
11
+
12
+ - descriptor: scalar ops previously left `child_plans[0]` in place for every row, wrapping scalar text in spurious `<>Hi </>` element shells during native emission.
13
+
14
+ Uniword model_serialize: 0.878s vs 2.52s baseline (~3x CPU), allocations 1.22M vs 3.07M (~2.5x). Engine suite 2222/2222.
15
+
16
+ ## [1.9.405] - 2026-11-03
17
+
18
+ ### Fixed
19
+
20
+ - **XSD: the leptris-rs#36 attribute leg** — an attribute with
21
+ `fixed` whose instance lexical differs only in whitespace was
22
+ rejected by the raw strcmp. The fixed constraint holds on the
23
+ TYPE's value (§3.2.3/§4.3.1.2): when the raw comparison fails,
24
+ both sides normalize per the type's whiteSpace and compare again
25
+ (addB104, attO006 — xsd:integer whitespace variants).
26
+
27
+ - **XSD: nested attributeGroup refs (leptris#1957)** — an inner
28
+ `attributeGroup ref` naming a group declared LATER expanded empty,
29
+ rejecting level-2 members under strict admission (attgD005..034,
30
+ attJ018). The pre-pass registers every def first and captures rows
31
+ in a second sweep; the ref expansion re-captures lazily through
32
+ the def's own element. A complexType whose content model is only
33
+ an attributeGroup ref + `mixed="true"` no longer reports "the
34
+ content model is empty".
35
+
36
+ - **XSD: multi-document component resolution (leptris#1958)** — an
37
+ import of a no-targetNamespace document kept the importer's tns
38
+ during capture (chameleon semantics are include-only, §4.2.3), so
39
+ its same-named complexType shadowed the importing namespace's own
40
+ declaration and swapped particle types (schF1). The content-model
41
+ child loop binds a no-namespace child to its own no-tns
42
+ declaration first; `xs:redefine` of a simpleType aliases the
43
+ original so the facet chain resolves to the redefinition (schP2's
44
+ minLength enforced).
45
+
46
+ - **Descriptor: retained captured sub-documents until schema
47
+ teardown** — the #1957 lazy attributeGroup expansion holds element
48
+ pointers into their own unit; freeing sub-documents at chase time
49
+ left them dangling (heap-use-after-free under ASAN in the corpus
50
+ sweep).
51
+
52
+
53
+
3
54
  ## [1.9.404] - 2026-11-03
4
55
 
5
56
  ### Fixed
@@ -3,7 +3,7 @@
3
3
  cmake_minimum_required(VERSION 3.20)
4
4
 
5
5
  project(leptris
6
- VERSION 1.9.404
6
+ VERSION 1.9.406
7
7
  DESCRIPTION "Fast XML parser and XPath evaluator in pure C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -277,7 +277,15 @@ typedef enum {
277
277
  LEPTRIS_PLAN_OP_SCALAR = 0,
278
278
  LEPTRIS_PLAN_OP_ELEMENT = 1,
279
279
  LEPTRIS_PLAN_OP_ATTR = 2,
280
- LEPTRIS_PLAN_OP_END = 3
280
+ LEPTRIS_PLAN_OP_END = 3,
281
+ /* leptris#1941: splice a host-serialized fragment verbatim —
282
+ * `value`/`value_len` carry the fragment; the result stores it as
283
+ * a VALUE_RAW and the serializer emits it without escaping. The
284
+ * ops lane's escape hatch for subtrees the plan cannot address
285
+ * (valued cycle-point rows: the child model serializes through
286
+ * its own lane and rides as text). plan_index/row_index are
287
+ * ignored. */
288
+ LEPTRIS_PLAN_OP_RAW = 4
281
289
  } LeptrisPlanRowOpKind;
282
290
 
283
291
  typedef struct {
@@ -2044,6 +2044,11 @@ static struct leptris_plan_result* plan_result_build_windowed(
2044
2044
  dp_value_new(LEPTRIS_PLAN_VALUE_SCALAR);
2045
2045
  if (!v) goto oom;
2046
2046
  const dp_plan* cp = &pool->plans[op->plan_index];
2047
+ /* The row identity drives the serializer's CONTENT check
2048
+ * (bare text vs the wrapper element) and host row
2049
+ * attribution — stamp it from the op. */
2050
+ v->row_index = op->row_index;
2051
+ v->container_plan = op->plan_index;
2047
2052
  if (op->row_index < cp->child_count)
2048
2053
  v->name = dp_strdup(
2049
2054
  cp->child_plans[op->row_index].wire_name);
@@ -2160,6 +2165,27 @@ static struct leptris_plan_result* plan_result_build_windowed(
2160
2165
  if (!gn[el->attr_count] || !gv[el->attr_count])
2161
2166
  goto oom;
2162
2167
  el->attr_count++;
2168
+ } else if (op->kind == LEPTRIS_PLAN_OP_RAW) {
2169
+ /* leptris#1941: the host-serialized fragment rides the
2170
+ * result verbatim (VALUE_RAW; the serializer emits it
2171
+ * without escaping). Ignored by hydration. */
2172
+ struct leptris_plan_result* v =
2173
+ dp_value_new(LEPTRIS_PLAN_VALUE_RAW);
2174
+ if (!v) goto oom;
2175
+ if (!dp_value_set_str(v, op->value ? op->value : "",
2176
+ op->value ? op->value_len : 0))
2177
+ dp_value_set_str(v, "", 0);
2178
+ if (sp == 0) {
2179
+ dp_result_free_rec(v);
2180
+ free(stack);
2181
+ if (status) *status = LEPTRIS_ERROR_INVALID_ARG;
2182
+ return NULL;
2183
+ }
2184
+ v->order_index = (uint32_t)stack[sp - 1]->kid_count;
2185
+ if (!dp_value_push(stack[sp - 1], v)) {
2186
+ dp_result_free_rec(v);
2187
+ goto oom;
2188
+ }
2163
2189
  } else if (op->kind == LEPTRIS_PLAN_OP_END) {
2164
2190
  if (sp == 0) {
2165
2191
  /* Mid-build failure: the arena holds every minted
@@ -62,6 +62,12 @@ struct leptris_xsd_schema {
62
62
  * re-captures the whole subtree (multi-GB / minutes). */
63
63
  char** visited;
64
64
  size_t visited_len, visited_cap;
65
+ /* leptris#1957: captured sub-documents stay ALIVE until schema
66
+ * teardown — attributeGroup defs hold LeptrisElement pointers
67
+ * into their own unit for the lazy ref expansion, and freeing
68
+ * the sub-document at chase time left those dangling (ASAN
69
+ * heap-use-after-free in the corpus sweep). */
70
+ struct xsd_sub_doc* sub_docs;
65
71
  void* validator; /* slice-4 parked error list */
66
72
  char* error;
67
73
  /* #1841: materialized structured report — rebuilt per
@@ -550,6 +556,11 @@ static ret_type fn_name(struct leptris_xsd_schema* s, const char* name, \
550
556
  return t; \
551
557
  return NULL; \
552
558
  } \
559
+ /* NULL uri: the reference itself is namespace-free — unstamped \
560
+ * declarations bind FIRST (leptris#1958: an imported \
561
+ * no-targetNamespace type must win its own reference over the \
562
+ * importing namespace's same-name type), then the policy allows \
563
+ * the name-only sweep across the merged table. */ \
553
564
  for (ret_type t = s->list_field; t; t = t->next) \
554
565
  if (strcmp(t->name_field, name) == 0) \
555
566
  return t; \
@@ -558,6 +569,25 @@ static ret_type fn_name(struct leptris_xsd_schema* s, const char* name, \
558
569
 
559
570
  XSD_DEFINE_NS_LADDER(const XsdElementDecl*, xsd_ladder_element, elements,
560
571
  name, ns)
572
+
573
+ /* leptris#1958: a NULL-namespace INSTANCE element binds its own
574
+ * no-targetNamespace declaration FIRST — the importing namespace's
575
+ * same-name global (registered later, prepended earlier in the
576
+ * merged list) must not shadow it. Stamped references keep the
577
+ * macro's ladder. */
578
+ const XsdElementDecl* xsd_ladder_element_ns_free_first(
579
+ struct leptris_xsd_schema* s, const char* name, const char* uri,
580
+ int allow_name_only) {
581
+ if (!s || !name) return NULL;
582
+ if (uri && uri[0])
583
+ return xsd_ladder_element(s, name, uri, allow_name_only);
584
+ for (XsdElementDecl* t = s->elements; t; t = t->next)
585
+ if (!t->ns && strcmp(t->name, name) == 0) return t;
586
+ if (!allow_name_only) return NULL;
587
+ for (XsdElementDecl* t = s->elements; t; t = t->next)
588
+ if (strcmp(t->name, name) == 0) return t;
589
+ return NULL;
590
+ }
561
591
  XSD_DEFINE_NS_LADDER(XsdCm*, xsd_ladder_complex, complex_types, name, ns)
562
592
  XSD_DEFINE_NS_LADDER(const XsdSimple*, xsd_ladder_simple, simple_types,
563
593
  name, ns)
@@ -2293,6 +2323,23 @@ static int xsd_visited_has(struct leptris_xsd_schema* s,
2293
2323
  return 0;
2294
2324
  }
2295
2325
 
2326
+ struct xsd_sub_doc {
2327
+ LeptrisDocument doc;
2328
+ struct xsd_sub_doc* next;
2329
+ };
2330
+
2331
+ static void xsd_sub_doc_retain(struct leptris_xsd_schema* s,
2332
+ LeptrisDocument doc) {
2333
+ struct xsd_sub_doc* node =
2334
+ (struct xsd_sub_doc*)calloc(1, sizeof(*node));
2335
+ if (!node) return; /* retention is best-effort; the freed-elem
2336
+ lazy path is never taken for eagerly
2337
+ captured defs */
2338
+ node->doc = doc;
2339
+ node->next = (struct xsd_sub_doc*)s->sub_docs;
2340
+ s->sub_docs = node;
2341
+ }
2342
+
2296
2343
  static void xsd_visited_add(struct leptris_xsd_schema* s,
2297
2344
  const char* path) {
2298
2345
  if (s->visited_len == s->visited_cap) {
@@ -2313,20 +2360,29 @@ static XsdAttrDecl* xsd_capture_attr_rows(
2313
2360
  * PRE-PASS — the symbol space is order-free, but the ref expansion
2314
2361
  * in xsd_capture_attr_rows looks up s->attr_groups at capture time,
2315
2362
  * so a group declared AFTER the referencing type used to vanish. */
2316
- static void xsd_capture_attr_group_def(struct leptris_xsd_schema* s,
2317
- LeptrisElement n,
2318
- const char* nm) {
2363
+ /* Phase 1 registers the def (name + element) only; phase 2
2364
+ * captures the rows once EVERY top-level group is registered —
2365
+ * leptris#1957: an inner attributeGroup ref naming a group that
2366
+ * appears LATER in the document used to expand empty. */
2367
+ static void xsd_register_attr_group_def(struct leptris_xsd_schema* s,
2368
+ LeptrisElement n,
2369
+ const char* nm) {
2319
2370
  XsdAttrGroupDef* g = (XsdAttrGroupDef*)calloc(1, sizeof(*g));
2320
2371
  if (!g) return;
2321
2372
  g->name = xsd_strdup(nm);
2322
- g->attrs = xsd_capture_attr_rows(s, n, 0);
2373
+ g->elem = n;
2323
2374
  g->next = s->attr_groups;
2324
2375
  s->attr_groups = g;
2325
2376
  }
2326
2377
 
2327
2378
  static void xsd_capture_root(struct leptris_xsd_schema* s,
2328
2379
  LeptrisElement root) {
2329
- /* pre-pass: every top-level attributeGroup def, document order */
2380
+ /* pre-pass phase 1: register every top-level attributeGroup def
2381
+ * (name + element), document order — the symbol space is
2382
+ * order-free. Phase 2 captures the rows once ALL defs are
2383
+ * registered, so an inner attributeGroup ref naming a LATER
2384
+ * group resolves (leptris#1957: level-2 members used to
2385
+ * vanish). */
2330
2386
  for (LeptrisNodeRef n =
2331
2387
  leptris_node_first_child(leptris_element_as_node(root));
2332
2388
  n; n = leptris_node_next_sibling(n)) {
@@ -2342,8 +2398,11 @@ static void xsd_capture_root(struct leptris_xsd_schema* s,
2342
2398
  const char* nm = leptris_element_attribute((LeptrisElement)n,
2343
2399
  "name");
2344
2400
  if (!nm) continue;
2345
- xsd_capture_attr_group_def(s, (LeptrisElement)n, nm);
2401
+ xsd_register_attr_group_def(s, (LeptrisElement)n, nm);
2346
2402
  }
2403
+ for (XsdAttrGroupDef* g = s->attr_groups; g; g = g->next)
2404
+ if (!g->attrs && g->elem)
2405
+ g->attrs = xsd_capture_attr_rows(s, g->elem, 0);
2347
2406
  for (LeptrisNodeRef n =
2348
2407
  leptris_node_first_child(leptris_element_as_node(root));
2349
2408
  n; n = leptris_node_next_sibling(n)) {
@@ -2416,11 +2475,23 @@ static void xsd_capture_root(struct leptris_xsd_schema* s,
2416
2475
  (strcmp(local, "import") == 0 || same_ns)) {
2417
2476
  /* leptris-ruby#440/#439: each captured
2418
2477
  * unit stamps ITS OWN targetNamespace on
2419
- * its declarations — chameleon includes
2420
- * (no tns) adopt the includer's. */
2478
+ * its declarations — chameleon INCLUDES
2479
+ * (no tns) adopt the includer's.
2480
+ * leptris#1958: an IMPORT of a
2481
+ * no-targetNamespace document keeps its
2482
+ * declarations namespace-FREE (XSD 1.0
2483
+ * §4.2.3 — chameleon semantics are
2484
+ * include-only); stamping the importer's
2485
+ * tns made its same-named components
2486
+ * shadow the importing namespace's own
2487
+ * (schF1: the imported ct-A won the
2488
+ * (ns-a, ct-A) exact ladder slot and
2489
+ * swapped a1/a2's types). */
2421
2490
  char* saved_ns = s->target_ns;
2422
2491
  char* sub_ns = tns ? xsd_strdup(tns) : NULL;
2423
2492
  if (sub_ns) s->target_ns = sub_ns;
2493
+ else if (strcmp(local, "import") == 0)
2494
+ s->target_ns = NULL;
2424
2495
  s->include_depth++;
2425
2496
  xsd_capture_root(s, subroot);
2426
2497
  s->include_depth--;
@@ -2446,8 +2517,47 @@ static void xsd_capture_root(struct leptris_xsd_schema* s,
2446
2517
  xsd_capture_root(s, (LeptrisElement)n);
2447
2518
  s->capture_force = 0;
2448
2519
  s->include_depth--;
2520
+ /* leptris#1958 (schP2): a redefined
2521
+ * simpleType's restriction base names the
2522
+ * ORIGINAL definition — both share the
2523
+ * name, and the name-only chain lookup
2524
+ * (head-first = the replacement) would
2525
+ * self-loop. Rename the original to a
2526
+ * hidden alias and repoint the
2527
+ * replacement's base at it; every OTHER
2528
+ * reference keeps resolving to the
2529
+ * replacement (head-first). */
2530
+ for (XsdSimple* t = s->simple_types; t;
2531
+ t = t->next) {
2532
+ if (!t->base || strcmp(t->base, t->name) != 0)
2533
+ continue;
2534
+ XsdSimple* other = NULL;
2535
+ for (XsdSimple* o = s->simple_types; o;
2536
+ o = o->next) {
2537
+ if (o == t) continue;
2538
+ if (o->name &&
2539
+ strcmp(o->name, t->name) == 0) {
2540
+ other = o;
2541
+ break;
2542
+ }
2543
+ }
2544
+ if (!other) continue;
2545
+ size_t alen = strlen(other->name) + 24;
2546
+ char* alias =
2547
+ (char*)malloc(alen);
2548
+ if (!alias) continue;
2549
+ snprintf(alias, alen, "%s#rb%p",
2550
+ other->name, (void*)other);
2551
+ free(other->name);
2552
+ other->name = alias;
2553
+ free(t->base);
2554
+ t->base = xsd_strdup(alias);
2555
+ }
2449
2556
  }
2450
- leptris_document_free(sub);
2557
+ /* leptris#1957: retained — attributeGroup
2558
+ * defs hold elements from this unit for the
2559
+ * lazy ref expansion; freed at teardown. */
2560
+ xsd_sub_doc_retain(s, sub);
2451
2561
  }
2452
2562
  free(text);
2453
2563
  }
@@ -2593,8 +2703,16 @@ static void xsd_capture_root(struct leptris_xsd_schema* s,
2593
2703
  XsdAttrGroupDef* seen = s->attr_groups;
2594
2704
  for (; seen; seen = seen->next)
2595
2705
  if (strcmp(seen->name, nm) == 0) break;
2596
- if (!seen || s->capture_force)
2597
- xsd_capture_attr_group_def(s, (LeptrisElement)n, nm);
2706
+ if (!seen || s->capture_force) {
2707
+ /* Sub-document defs register + capture inline —
2708
+ * their own inner refs ride the same lazy
2709
+ * expansion (leptris#1957). */
2710
+ xsd_register_attr_group_def(s, (LeptrisElement)n, nm);
2711
+ XsdAttrGroupDef* rg = s->attr_groups;
2712
+ if (rg && !rg->attrs)
2713
+ rg->attrs =
2714
+ xsd_capture_attr_rows(s, rg->elem, 0);
2715
+ }
2598
2716
  }
2599
2717
  } else if (strcmp(local, "group") == 0 && uri && !strcmp(uri, XSD_NS)) {
2600
2718
  const char* nm =
@@ -2663,6 +2781,15 @@ static void xsd_free_simple_one(XsdSimple* t) {
2663
2781
  LEPTRIS_API void leptris_xsd_free(LeptrisXsdSchema schema) {
2664
2782
  struct leptris_xsd_schema* s = (struct leptris_xsd_schema*)schema;
2665
2783
  if (!s) return;
2784
+ /* leptris#1957: retained sub-documents last — attributeGroup
2785
+ * defs' LeptrisElement pointers live inside them. */
2786
+ struct xsd_sub_doc* sd = (struct xsd_sub_doc*)s->sub_docs;
2787
+ while (sd) {
2788
+ struct xsd_sub_doc* sn = sd->next;
2789
+ leptris_document_free(sd->doc);
2790
+ free(sd);
2791
+ sd = sn;
2792
+ }
2666
2793
  free(s->report);
2667
2794
  xsd_cm_free(s->complex_types);
2668
2795
  XsdElementIcs* slot = s->element_ics;
@@ -3451,8 +3578,15 @@ static XsdAttrDecl* xsd_capture_attr_rows(struct leptris_xsd_schema* s,
3451
3578
  XsdAttrGroupDef* g = s->attr_groups;
3452
3579
  for (; g; g = g->next)
3453
3580
  if (strcmp(g->name, ref) == 0) break;
3454
- if (!g || !g->attrs) continue;
3455
- XsdAttrDecl* copied = xsd_copy_attr_rows(g->attrs);
3581
+ if (!g) continue;
3582
+ /* leptris#1957: expand lazily through the def's own
3583
+ * element when its rows are not captured yet (a group
3584
+ * registered in phase 1 whose phase-2 capture has not
3585
+ * run, or runs later in document order). depth+1 keeps
3586
+ * the cycle guard. */
3587
+ XsdAttrDecl* copied =
3588
+ g->attrs ? xsd_copy_attr_rows(g->attrs)
3589
+ : xsd_capture_attr_rows(s, g->elem, depth + 1);
3456
3590
  if (!copied) continue;
3457
3591
  if (!head)
3458
3592
  head = copied;
@@ -3703,6 +3837,23 @@ const XsdElementDecl* xsd_find_element_ns(
3703
3837
  return xsd_ladder_element(s, name, uri, 0);
3704
3838
  }
3705
3839
 
3840
+ /* leptris#1958: the CONTENT-MODEL child loop's lookup — a
3841
+ * no-namespace instance child binds its own no-targetNamespace
3842
+ * declaration FIRST (the importing namespace's same-name global
3843
+ * sits ahead in the merged list and must not shadow it). Root and
3844
+ * global lookups keep the stock ladder. */
3845
+ const XsdElementDecl* xsd_find_element_child_ns(
3846
+ struct leptris_xsd_schema* s, const char* name, const char* uri) {
3847
+ if (!s || !name) return NULL;
3848
+ if (uri && uri[0])
3849
+ return xsd_ladder_element(s, name, uri, 0);
3850
+ for (XsdElementDecl* t = s->elements; t; t = t->next)
3851
+ if (!t->ns && strcmp(t->name, name) == 0) return t;
3852
+ for (XsdElementDecl* t = s->elements; t; t = t->next)
3853
+ if (strcmp(t->name, name) == 0) return t;
3854
+ return NULL;
3855
+ }
3856
+
3706
3857
  XsdCm* xsd_find_complex(struct leptris_xsd_schema* s,
3707
3858
  const char* type_name) {
3708
3859
  if (!s || !type_name) return NULL;
@@ -3721,6 +3872,22 @@ XsdCm* xsd_find_complex_ns(struct leptris_xsd_schema* s,
3721
3872
  return xsd_ladder_complex(s, type_name, uri, 0);
3722
3873
  }
3723
3874
 
3875
+ /* leptris#1958: the ns-FREE reference — a no-targetNamespace
3876
+ * declaration's unprefixed type binds ITS OWN unit's (unstamped)
3877
+ * component first; the importing namespace's same-name type (which
3878
+ * sits ahead in the merged list) must not shadow it. Used only by
3879
+ * the validator's decl-driven fallback (hint == NULL, instance
3880
+ * namespace absent) — every other lookup keeps the stock ladder. */
3881
+ XsdCm* xsd_find_complex_ns_free_first(struct leptris_xsd_schema* s,
3882
+ const char* type_name) {
3883
+ if (!s || !type_name) return NULL;
3884
+ for (XsdCm* t = s->complex_types; t; t = t->next)
3885
+ if (!t->ns && strcmp(t->name, type_name) == 0) return t;
3886
+ for (XsdCm* t = s->complex_types; t; t = t->next)
3887
+ if (strcmp(t->name, type_name) == 0) return t;
3888
+ return NULL;
3889
+ }
3890
+
3724
3891
  /* leptris-ruby#440 (follow-up): a TYPE REFERENCE on an instance
3725
3892
  * element resolves against the namespace the REFERENCE declares —
3726
3893
  * OOXML's dml family types every wp:/pic: particle with
@@ -36,10 +36,14 @@ extern const XsdElementDecl* xsd_find_element_ns(
36
36
  struct leptris_xsd_schema* s, const char* name, const char* uri);
37
37
  extern const XsdElementDecl* xsd_find_element(
38
38
  struct leptris_xsd_schema* s, const char* name);
39
+ extern const XsdElementDecl* xsd_find_element_child_ns(
40
+ struct leptris_xsd_schema* s, const char* name, const char* uri);
39
41
  extern XsdCm* xsd_find_complex_ns(struct leptris_xsd_schema* s,
40
42
  const char* type_name, const char* uri);
41
43
  extern XsdCm* xsd_find_complex_ref(struct leptris_xsd_schema* s,
42
44
  const char* type_name, const char* uri);
45
+ extern XsdCm* xsd_find_complex_ns_free_first(struct leptris_xsd_schema* s,
46
+ const char* type_name);
43
47
  XsdCm* xsd_find_complex(struct leptris_xsd_schema* s, const char* type_name);
44
48
  extern const XsdSimple* xsd_find_simple_ns_pub(
45
49
  struct leptris_xsd_schema* s, const char* name, const char* uri);
@@ -297,15 +301,21 @@ static int text_valid(struct xsd_validator* v,
297
301
  static void validate_element(struct xsd_validator* v,
298
302
  struct leptris_xsd_schema* s,
299
303
  LeptrisElement elem, int depth);
304
+ static void validate_element_decl(struct xsd_validator* v,
305
+ struct leptris_xsd_schema* s,
306
+ LeptrisElement elem, int depth,
307
+ const XsdElementDecl* decl_override);
300
308
  static void validate_local(struct xsd_validator* v,
301
309
  struct leptris_xsd_schema* s,
302
310
  LeptrisElement elem, const char* local,
303
- const char* type, const char* fill);
311
+ const char* type, const char* fill,
312
+ const char* tns_hint);
304
313
  static void validate_local_uri(struct xsd_validator* v,
305
314
  struct leptris_xsd_schema* s,
306
315
  LeptrisElement elem, const char* local,
307
316
  const char* type, const char* euri,
308
- const char* xsi_q, const char* fill);
317
+ const char* xsi_q, const char* fill,
318
+ const char* tns_hint);
309
319
 
310
320
  /* #1879: the strongest processContents among the model's wildcards
311
321
  * whose namespace grammar admits (uri) — 2 skip, 1 lax, 0 strict,
@@ -549,13 +559,16 @@ static void validate_children(struct xsd_validator* v,
549
559
  "xsi:type prefix is not bound in the instance");
550
560
  } else {
551
561
  validate_local_uri(v, s, ce, cl, xlocal, xuri, cxsi,
552
- pfill);
562
+ pfill, NULL);
553
563
  }
554
564
  } else {
555
- validate_local(v, s, ce, cl, ptype, pfill);
565
+ validate_local(v, s, ce, cl, ptype, pfill,
566
+ ct ? ct->ns : NULL);
556
567
  }
557
- } else if (xsd_find_element_ns(s, cl, cu)) {
558
- validate_element(v, s, ce, 0);
568
+ } else {
569
+ const XsdElementDecl* cd =
570
+ xsd_find_element_child_ns(s, cl, cu);
571
+ if (cd) validate_element_decl(v, s, ce, 0, cd);
559
572
  }
560
573
  /* wildcard-admitted children without a declaration pass:
561
574
  * strict and lax alike admit undeclared names (the pinned
@@ -665,6 +678,43 @@ static int any_attr_matches(const char* grammar, const char* uri,
665
678
  return 0;
666
679
  }
667
680
 
681
+ /* leptris-rs#36 (addB104, attO006): the fixed constraint holds on
682
+ * the TYPE's value, not the raw lexical (XSD 1.0 §3.2.3/§4.3.1.2) —
683
+ * a whitespace-variant lexical of a collapsing type (token family,
684
+ * numeric) is the same value. Normalize both per the type's
685
+ * whiteSpace and compare. */
686
+ static int attr_fixed_matches(struct leptris_xsd_schema* s,
687
+ const char* type, const char* ns,
688
+ const char* val, const char* fixed) {
689
+ if (!type) return 0;
690
+ if (!type_collapses_ws(s, type, ns)) return 0;
691
+ char norm_v[512];
692
+ char norm_f[512];
693
+ size_t n = strlen(val);
694
+ if (n >= sizeof(norm_v)) return 0;
695
+ size_t m = strlen(fixed);
696
+ if (m >= sizeof(norm_f)) return 0;
697
+ for (int pass = 0; pass < 2; pass++) {
698
+ const char* src = pass ? fixed : val;
699
+ char* out = pass ? norm_f : norm_v;
700
+ char* o = out;
701
+ const char* p = src;
702
+ while (*p && isspace((unsigned char)*p)) p++;
703
+ int spaced = 0;
704
+ while (*p) {
705
+ if (isspace((unsigned char)*p)) {
706
+ spaced = 1;
707
+ p++;
708
+ continue;
709
+ }
710
+ if (spaced) { *o++ = ' '; spaced = 0; }
711
+ *o++ = *p++;
712
+ }
713
+ *o = 0;
714
+ }
715
+ return strcmp(norm_v, norm_f) == 0;
716
+ }
717
+
668
718
  static void validate_attributes(struct xsd_validator* v,
669
719
  struct leptris_xsd_schema* s,
670
720
  LeptrisElement elem,
@@ -703,7 +753,9 @@ static void validate_attributes(struct xsd_validator* v,
703
753
  }
704
754
  text_valid(v, s, a->type, val, ta ? ta->ns : NULL, "attribute",
705
755
  a->name, elem);
706
- if (a->fixed && strcmp(val, a->fixed) != 0)
756
+ if (a->fixed && strcmp(val, a->fixed) != 0 &&
757
+ !attr_fixed_matches(s, a->type, ta ? ta->ns : NULL, val,
758
+ a->fixed))
707
759
  verrf_atk(v, elem, "attribute-use", a->name, "attribute",
708
760
  a->name, "value does not match the fixed value");
709
761
  }
@@ -798,13 +850,24 @@ static void validate_attributes(struct xsd_validator* v,
798
850
  static void validate_element(struct xsd_validator* v,
799
851
  struct leptris_xsd_schema* s,
800
852
  LeptrisElement elem, int depth) {
853
+ validate_element_decl(v, s, elem, depth, NULL);
854
+ }
855
+
856
+ /* decl_override: the CALLER's ns-free declaration find (the content
857
+ * model child loop's leptris#1958 semantics) — NULL = resolve here. */
858
+ static void validate_element_decl(struct xsd_validator* v,
859
+ struct leptris_xsd_schema* s,
860
+ LeptrisElement elem, int depth,
861
+ const XsdElementDecl* decl_override) {
801
862
  if (depth > 64) return;
802
863
  const char* local = NULL, *prefix = NULL, *uri = NULL;
803
864
  leptris_element_expanded_name(elem, &local, &prefix, &uri);
804
865
  if (!local) return;
805
866
  const char* guri = NULL;
806
867
  leptris_element_expanded_name(elem, NULL, NULL, &guri);
807
- const XsdElementDecl* d = xsd_find_element_ns(s, local, guri);
868
+ const XsdElementDecl* d =
869
+ decl_override ? decl_override
870
+ : xsd_find_element_ns(s, local, guri);
808
871
  if (!d) {
809
872
  /* strict: the instance uses an element the schema never
810
873
  * declared (a local particle would have typed it) */
@@ -882,10 +945,11 @@ static void validate_element(struct xsd_validator* v,
882
945
  return;
883
946
  }
884
947
  validate_local_uri(v, s, elem, local, xlocal, xuri, xsi_q,
885
- fill);
948
+ fill, NULL);
886
949
  return;
887
950
  }
888
- validate_local(v, s, elem, local, eff_type, fill);
951
+ validate_local(v, s, elem, local, eff_type, fill,
952
+ d->ns);
889
953
  }
890
954
 
891
955
  /* Validate one element against a type name that comes from a
@@ -894,22 +958,43 @@ static void validate_element(struct xsd_validator* v,
894
958
  static void validate_local(struct xsd_validator* v,
895
959
  struct leptris_xsd_schema* s,
896
960
  LeptrisElement elem, const char* local,
897
- const char* type, const char* fill) {
961
+ const char* type, const char* fill,
962
+ const char* tns_hint);
963
+ static void validate_local_uri(struct xsd_validator* v,
964
+ struct leptris_xsd_schema* s,
965
+ LeptrisElement elem, const char* local,
966
+ const char* type, const char* euri,
967
+ const char* xsi_q, const char* fill,
968
+ const char* tns_hint);
969
+
970
+ static void validate_local(struct xsd_validator* v,
971
+ struct leptris_xsd_schema* s,
972
+ LeptrisElement elem, const char* local,
973
+ const char* type, const char* fill,
974
+ const char* tns_hint) {
898
975
  const char* euri = NULL;
899
976
  leptris_element_expanded_name(elem, NULL, NULL, &euri);
900
- validate_local_uri(v, s, elem, local, type, euri, NULL, fill);
977
+ validate_local_uri(v, s, elem, local, type, euri, NULL, fill,
978
+ tns_hint);
901
979
  }
902
980
 
903
981
  static void validate_local_uri(struct xsd_validator* v,
904
982
  struct leptris_xsd_schema* s,
905
983
  LeptrisElement elem, const char* local,
906
984
  const char* type, const char* euri,
907
- const char* xsi_q, const char* fill) {
985
+ const char* xsi_q, const char* fill,
986
+ const char* tns_hint) {
908
987
  if (!type) return;
909
- /* the type ref may name a FOREIGN namespace's type (OOXML:
910
- * wp:extent -> a:CT_PositiveSize2D) — resolve through the
911
- * reference ladder, not the element-ns-strict lookup */
912
- XsdCm* ct = xsd_find_complex_ref(s, type, euri);
988
+ /* leptris#1958: the DECLARING unit's targetNamespace binds the
989
+ * type reference first — a no-targetNamespace declaration's
990
+ * unprefixed type must resolve to ITS OWN unit's component, not
991
+ * the importing namespace's same-name type (schF1). The
992
+ * instance-ns reference ladder remains the fallback (OOXML:
993
+ * wp:extent -> a:CT_PositiveSize2D — #1687). */
994
+ XsdCm* ct = tns_hint ? xsd_find_complex_ns(s, type, tns_hint) : NULL;
995
+ if (!ct && (!euri || !euri[0]))
996
+ ct = xsd_find_complex_ns_free_first(s, type);
997
+ if (!ct) ct = xsd_find_complex_ref(s, type, euri);
913
998
  /* XSD 1.0 §2.7/§3.3.3 (leptris-rs#26, particlesIa002/
914
999
  * QFE1700g2): a NILLED element must have neither character nor
915
1000
  * element content — the content model is not applied (the nil
@@ -255,6 +255,11 @@ typedef struct xsd_element_ics {
255
255
  typedef struct xsd_attrgroup_def {
256
256
  char* name;
257
257
  XsdAttrDecl* attrs;
258
+ /* leptris#1957: the definition's own element — the ref
259
+ * expansion RE-CAPTURES it lazily so an inner attributeGroup ref
260
+ * naming a LATER-registered group resolves (document-order
261
+ * capture used to leave level-2 members unexpanded). */
262
+ LeptrisElement elem;
258
263
  struct xsd_attrgroup_def* next;
259
264
  } XsdAttrGroupDef;
260
265
 
@@ -156,6 +156,9 @@ target_compile_definitions(test_xsd_compile PRIVATE
156
156
  leptris_add_test(test_rs35_regression xsd/test_rs35_regression.cpp)
157
157
  target_compile_definitions(test_rs35_regression PRIVATE
158
158
  LEPTRIS_XSD_CASES_DIR="${CMAKE_CURRENT_SOURCE_DIR}/xsd/libxml2-cases")
159
+ leptris_add_test(test_i1957_1958 xsd/test_i1957_1958.cpp)
160
+ target_compile_definitions(test_i1957_1958 PRIVATE
161
+ LEPTRIS_XSD_CASES_DIR="${CMAKE_CURRENT_SOURCE_DIR}/xsd/libxml2-cases")
159
162
  target_compile_definitions(test_rng PRIVATE
160
163
  LEPTRIS_RNG_INCLUDE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/rng/include-cases")
161
164
  leptris_add_test(test_rng_corpus rng/test_rng_corpus.cpp)
@@ -2577,6 +2577,45 @@ TEST(Plan1941, ResultBuildInheritsPlanAndChildPlanBindings) {
2577
2577
  * the #1115 multi-ns case carry no row binding and take the
2578
2578
  * child plan's w14/w15 namespaces, while a row WITH a binding
2579
2579
  * keeps it verbatim. */
2580
+ /* leptris#1941: the RAW op splices a host-serialized fragment into
2581
+ * the result verbatim — the ops lane's escape hatch for subtrees
2582
+ * the plan cannot address (valued child_deferred rows: the child
2583
+ * model serializes through its own best lane and rides as text). */
2584
+ TEST(Plan1941, ResultBuildRawOpSplicesVerbatim) {
2585
+ LeptrisStatus st = LEPTRIS_OK;
2586
+ leptris_child_plan kids[1] = {};
2587
+ kids[0].wire_name = "p";
2588
+ kids[0].kind = LEPTRIS_PLAN_KIND_SCALAR;
2589
+ kids[0].child_plan_index = -1;
2590
+ leptris_element_plan plans[1] = {};
2591
+ plans[0].element_name = "doc";
2592
+ plans[0].child_count = 1;
2593
+ plans[0].child_plans = kids;
2594
+ leptris_plan_spec spec = {};
2595
+ spec.abi_version = leptris_plan_abi_version();
2596
+ spec.plan_count = 1;
2597
+ spec.plans = plans;
2598
+ LeptrisPlan plan = leptris_plan_build(&spec, &st);
2599
+ ASSERT_NE(plan, nullptr);
2600
+
2601
+ const char* frag = "<w:r xmlns:w=\"urn:w\"><w:t>hi</w:t></w:r>";
2602
+ leptris_plan_row_op ops[] = {
2603
+ {LEPTRIS_PLAN_OP_ELEMENT, 0, UINT32_MAX, NULL, NULL, 0},
2604
+ {LEPTRIS_PLAN_OP_RAW, 0, UINT32_MAX, NULL, frag,
2605
+ (uint32_t)strlen(frag)},
2606
+ {LEPTRIS_PLAN_OP_END, 0, UINT32_MAX, NULL, NULL, 0},
2607
+ };
2608
+ LeptrisPlanResult r = leptris_plan_result_build(plan, ops, 3, &st);
2609
+ ASSERT_NE(r, nullptr);
2610
+ char* out = leptris_plan_serialize(plan, r, &st);
2611
+ ASSERT_NE(out, nullptr);
2612
+ EXPECT_STREQ(out,
2613
+ "<doc><w:r xmlns:w=\"urn:w\"><w:t>hi</w:t></w:r></doc>");
2614
+ leptris_free_string(out);
2615
+ leptris_plan_result_free(r);
2616
+ leptris_plan_free(plan);
2617
+ }
2618
+
2580
2619
  TEST(Plan1941, ResultBuildExplicitRowBindingBeatsInheritance) {
2581
2620
  LeptrisStatus st = LEPTRIS_OK;
2582
2621
  leptris_child_plan root_kids[2] = {};
@@ -0,0 +1,2 @@
1
+ <doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
+ xsi:noNamespaceSchemaLocation="schema.xsd" att1="x" foo="123">text</doc>
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0"?>
2
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3
+ <xsd:attribute name="att1" type="xsd:string"/>
4
+ <xsd:element name="doc">
5
+ <xsd:complexType mixed="true">
6
+ <xsd:attributeGroup ref="main"/>
7
+ </xsd:complexType>
8
+ </xsd:element>
9
+ <xsd:attributeGroup name="main">
10
+ <xsd:attribute ref="att1"/>
11
+ <xsd:attributeGroup ref="sub"/>
12
+ </xsd:attributeGroup>
13
+ <xsd:attributeGroup name="sub">
14
+ <xsd:attribute name="foo" type="xsd:int"/>
15
+ </xsd:attributeGroup>
16
+ </xsd:schema>
@@ -0,0 +1,14 @@
1
+ <a:root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
+ xsi:schemaLocation="ns-a schF1_a.xsd"
3
+ xmlns:a="ns-a"
4
+ >
5
+ <a:e1>
6
+ <a:a1>123</a:a1>
7
+ <a:a2>true</a:a2>
8
+ </a:e1>
9
+ <e1>
10
+ <a1>true</a1>
11
+ <a2>123</a2>
12
+ </e1>
13
+
14
+ </a:root>
@@ -0,0 +1,28 @@
1
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
2
+ targetNamespace="ns-a"
3
+ xmlns:a="ns-a"
4
+ elementFormDefault="qualified"
5
+ >
6
+
7
+ <xsd:import schemaLocation="schF1_b.xsd"/>
8
+
9
+ <xsd:complexType name="ct-A">
10
+ <xsd:sequence minOccurs="1">
11
+ <xsd:element name="a1" type="xsd:int" />
12
+ <xsd:element name="a2" type="xsd:boolean" />
13
+ </xsd:sequence>
14
+ </xsd:complexType>
15
+
16
+ <xsd:element name="e1" type="a:ct-A" />
17
+
18
+ <xsd:element name="root">
19
+ <xsd:complexType>
20
+ <xsd:choice maxOccurs="unbounded">
21
+ <xsd:any namespace="##any" processContents="strict"/>
22
+ </xsd:choice>
23
+ </xsd:complexType>
24
+ </xsd:element>
25
+
26
+ </xsd:schema>
27
+
28
+
@@ -0,0 +1,14 @@
1
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
2
+ elementFormDefault="qualified"
3
+ >
4
+
5
+ <xsd:complexType name="ct-A">
6
+ <xsd:sequence minOccurs="1">
7
+ <xsd:element name="a1" type="xsd:boolean" />
8
+ <xsd:element name="a2" type="xsd:int" />
9
+ </xsd:sequence>
10
+ </xsd:complexType>
11
+
12
+ <xsd:element name="e1" type="ct-A" />
13
+
14
+ </xsd:schema>
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0"?>
2
+ <e1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="ns-a" xsi:schemaLocation="ns-a schP2_a.xsd">abcd</e1>
@@ -0,0 +1,27 @@
1
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
2
+ targetNamespace="ns-a"
3
+ xmlns="ns-a"
4
+ elementFormDefault="qualified"
5
+ >
6
+
7
+ <xsd:redefine schemaLocation="schP2_b.xsd">
8
+ <xsd:simpleType name="b-st">
9
+ <xsd:restriction base="b-st">
10
+ <xsd:minLength value="4"/>
11
+ </xsd:restriction>
12
+ </xsd:simpleType>
13
+ </xsd:redefine>
14
+
15
+ <xsd:element name="e1" type="b-st" />
16
+
17
+ <xsd:element name="root">
18
+ <xsd:complexType>
19
+ <xsd:choice maxOccurs="unbounded">
20
+ <xsd:any namespace="##any" processContents="strict"/>
21
+ </xsd:choice>
22
+ </xsd:complexType>
23
+ </xsd:element>
24
+
25
+ </xsd:schema>
26
+
27
+
@@ -0,0 +1,12 @@
1
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
2
+ targetNamespace="ns-a"
3
+ xmlns="ns-a"
4
+ elementFormDefault="qualified"
5
+ >
6
+ <xsd:simpleType name="b-st">
7
+ <xsd:restriction base="xsd:string"/>
8
+ </xsd:simpleType>
9
+
10
+ <xsd:element name="b-e1" type="b-st" />
11
+
12
+ </xsd:schema>
@@ -0,0 +1,6 @@
1
+ <x:doc
2
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xmlns:x="ns"
4
+ xsi:schemaLocation="ns addB104.xsd">
5
+ <x:elem x:att=" 123 " />
6
+ </x:doc>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0"?>
2
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3
+ targetNamespace="ns"
4
+ xmlns:x='ns'
5
+ elementFormDefault="qualified"
6
+ attributeFormDefault="qualified">
7
+
8
+ <xsd:element name="doc">
9
+ <xsd:complexType>
10
+ <xsd:choice>
11
+ <xsd:element name="elem" >
12
+ <xsd:complexType>
13
+ <xsd:attribute name="att" type="xsd:integer" fixed=" 123 "/>
14
+ </xsd:complexType>
15
+ </xsd:element>
16
+ </xsd:choice>
17
+ </xsd:complexType>
18
+ </xsd:element>
19
+ </xsd:schema>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0"?>
2
+ <x:doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="http://xsdtesting" xsi:schemaLocation="http://xsdtesting attO006.xsd">
3
+ <x:elem x:att="123 "/>
4
+ </x:doc>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0"?>
2
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xsdtesting" xmlns:x="http://xsdtesting" elementFormDefault="qualified" attributeFormDefault="qualified">
3
+ <xsd:element name="doc">
4
+ <xsd:complexType>
5
+ <xsd:choice>
6
+ <xsd:element name="elem">
7
+ <xsd:complexType>
8
+ <xsd:attribute name="att" type="xsd:integer" fixed=" 123 ">
9
+ </xsd:attribute>
10
+ </xsd:complexType>
11
+ </xsd:element>
12
+ </xsd:choice>
13
+ </xsd:complexType>
14
+ </xsd:element>
15
+ </xsd:schema>
@@ -0,0 +1,90 @@
1
+ // leptris#1957 + leptris#1958 — two XSD component-resolution defects.
2
+ //
3
+ // #1957: nested attributeGroup refs — the level-2 members of a group
4
+ // referenced from inside another attributeGroup are rejected by
5
+ // strict admission (the pre-pass captures group defs in document
6
+ // order, so an inner ref that names a LATER group expands empty);
7
+ // and a complexType whose content model is only an attributeGroup
8
+ // ref + mixed="true" reported "the content model is empty".
9
+ //
10
+ // #1958: multi-document component resolution — an imported
11
+ // no-targetNamespace same-named complexType shadowed the importing
12
+ // namespace's own declaration, and xs:redefine'd simpleTypes were
13
+ // not registered ("type not found in the schema").
14
+ #include <gtest/gtest.h>
15
+
16
+ #include <cstdio>
17
+ #include <cstring>
18
+ #include <string>
19
+
20
+ #include "leptris.h"
21
+
22
+ namespace {
23
+
24
+ #ifndef LEPTRIS_XSD_CASES_DIR
25
+ #define LEPTRIS_XSD_CASES_DIR "libxml2-cases"
26
+ #endif
27
+
28
+ std::string cases_path(const char* sub) {
29
+ return std::string(LEPTRIS_XSD_CASES_DIR) + "/" + sub;
30
+ }
31
+
32
+ int validate_case(const std::string& schema, const std::string& doc) {
33
+ LeptrisStatus st = LEPTRIS_OK;
34
+ LeptrisXsdSchema s =
35
+ leptris_xsd_compile_file(schema.c_str(), &st);
36
+ if (!s) return -1;
37
+ LeptrisDocument d = leptris_parse_file(doc.c_str(), &st);
38
+ if (!d) {
39
+ leptris_xsd_free(s);
40
+ return -1;
41
+ }
42
+ int ok = leptris_xsd_validate(s, d);
43
+ if (getenv("I1958_VERBOSE"))
44
+ for (size_t i = 0; i < leptris_xsd_error_count(s); i++)
45
+ printf(" err: %s\n", leptris_xsd_error_at(s, i));
46
+ leptris_document_free(d);
47
+ leptris_xsd_free(s);
48
+ return ok;
49
+ }
50
+
51
+ } // namespace
52
+
53
+ TEST(I1957, NestedAttrGroupLevel2AdmitsAndMixedAdmitsText) {
54
+ EXPECT_EQ(validate_case(cases_path("i1957/schema.xsd"),
55
+ cases_path("i1957/instance.xml")),
56
+ 1);
57
+ }
58
+
59
+ TEST(I1958, ImportedSameNameTypeDoesNotShadow) {
60
+ EXPECT_EQ(validate_case(cases_path("i1958/schF1_a.xsd"),
61
+ cases_path("i1958/schF1.xml")),
62
+ 1);
63
+ }
64
+
65
+ TEST(I1958, RedefinedSimpleTypeRegistered) {
66
+ EXPECT_EQ(validate_case(cases_path("i1958/schP2_a.xsd"),
67
+ cases_path("i1958/schP2.xml")),
68
+ 1);
69
+ }
70
+
71
+ TEST(I1958, RedefinedSimpleTypeFacetEnforced) {
72
+ /* "abc" is 3 chars — the redefined minLength 4 rejects it (the
73
+ * facet proves the REDEFINED type, not the original, resolved). */
74
+ LeptrisStatus st = LEPTRIS_OK;
75
+ LeptrisXsdSchema s = leptris_xsd_compile_file(
76
+ cases_path("i1958/schP2_a.xsd").c_str(), &st);
77
+ ASSERT_NE(s, (LeptrisXsdSchema)0);
78
+ const char too_short[] =
79
+ "<e1 xmlns=\"ns-a\">abc</e1>";
80
+ LeptrisDocument d = leptris_parse_string(too_short,
81
+ strlen(too_short), &st);
82
+ ASSERT_NE(d, nullptr);
83
+ EXPECT_EQ(leptris_xsd_validate(s, d), 0)
84
+ << "minLength 4 rejected nothing";
85
+ size_t errs = leptris_xsd_error_count(s);
86
+ for (size_t i = 0; i < errs; i++)
87
+ printf(" err: %s\n", leptris_xsd_error_at(s, i));
88
+ leptris_document_free(d);
89
+ leptris_xsd_free(s);
90
+ }
@@ -93,6 +93,15 @@ int validate_pair(const Rs35Case& c) {
93
93
  }
94
94
  } // namespace
95
95
 
96
+ TEST(Rs35Regression, TheAttributeLegCasesValidate) {
97
+ /* leptris-rs#36: fixed + whitespace-variant lexicals — the
98
+ * fixed constraint holds on the TYPE value (§4.3.1.2), so
99
+ * integer attributes whose lexical differs only in
100
+ * whitespace validate. */
101
+ EXPECT_EQ(validate_pair({"attO006.xsd", "attO006.xml"}), 1);
102
+ EXPECT_EQ(validate_pair({"addB104.xsd", "addB104.xml"}), 1);
103
+ }
104
+
96
105
  TEST(Rs35Regression, AllFifteenW3cCasesValidate) {
97
106
  static const Rs35Case cases[] = {
98
107
  {"isdefault002.xsd", "isdefault005.xml"},
@@ -110,6 +119,8 @@ TEST(Rs35Regression, AllFifteenW3cCasesValidate) {
110
119
  {"idG027.xsd", "idG027.xml"},
111
120
  {"idG028.xsd", "idG028.xml"},
112
121
  {"stZ072.xsd", "stZ072.xml"},
122
+ {"attO006.xsd", "attO006.xml"},
123
+ {"addB104.xsd", "addB104.xml"},
113
124
  };
114
125
  for (const auto& c : cases)
115
126
  EXPECT_EQ(validate_pair(c), 1) << c.schema << " / " << c.instance;
@@ -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.404",
4
+ "version": "1.9.406",
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leptris
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.404.0
4
+ version: 1.9.406.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-03 00:00:00.000000000 Z
11
+ date: 2026-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -1406,6 +1406,14 @@ files:
1406
1406
  - vendor-src/libleptris/test/xsd/libxml2-cases/hexbinary_0.xml
1407
1407
  - vendor-src/libleptris/test/xsd/libxml2-cases/hexbinary_0.xsd
1408
1408
  - vendor-src/libleptris/test/xsd/libxml2-cases/hexbinary_1.xml
1409
+ - vendor-src/libleptris/test/xsd/libxml2-cases/i1957/instance.xml
1410
+ - vendor-src/libleptris/test/xsd/libxml2-cases/i1957/schema.xsd
1411
+ - vendor-src/libleptris/test/xsd/libxml2-cases/i1958/schF1.xml
1412
+ - vendor-src/libleptris/test/xsd/libxml2-cases/i1958/schF1_a.xsd
1413
+ - vendor-src/libleptris/test/xsd/libxml2-cases/i1958/schF1_b.xsd
1414
+ - vendor-src/libleptris/test/xsd/libxml2-cases/i1958/schP2.xml
1415
+ - vendor-src/libleptris/test/xsd/libxml2-cases/i1958/schP2_a.xsd
1416
+ - vendor-src/libleptris/test/xsd/libxml2-cases/i1958/schP2_b.xsd
1409
1417
  - vendor-src/libleptris/test/xsd/libxml2-cases/idc-keyref-err1_0.xml
1410
1418
  - vendor-src/libleptris/test/xsd/libxml2-cases/idc-keyref-err1_1.xsd
1411
1419
  - vendor-src/libleptris/test/xsd/libxml2-cases/import-455953.xsd
@@ -1507,6 +1515,10 @@ files:
1507
1515
  - vendor-src/libleptris/test/xsd/libxml2-cases/rs35_redefine_ext/idF025.xml
1508
1516
  - vendor-src/libleptris/test/xsd/libxml2-cases/rs35_redefine_ext/idF025.xsd
1509
1517
  - vendor-src/libleptris/test/xsd/libxml2-cases/rs35_redefine_ext/idF025_base.xsd
1518
+ - vendor-src/libleptris/test/xsd/libxml2-cases/rs35_w3c/addB104.xml
1519
+ - vendor-src/libleptris/test/xsd/libxml2-cases/rs35_w3c/addB104.xsd
1520
+ - vendor-src/libleptris/test/xsd/libxml2-cases/rs35_w3c/attO006.xml
1521
+ - vendor-src/libleptris/test/xsd/libxml2-cases/rs35_w3c/attO006.xsd
1510
1522
  - vendor-src/libleptris/test/xsd/libxml2-cases/rs35_w3c/ctA033.xml
1511
1523
  - vendor-src/libleptris/test/xsd/libxml2-cases/rs35_w3c/ctA033.xsd
1512
1524
  - vendor-src/libleptris/test/xsd/libxml2-cases/rs35_w3c/ctA035.xml
@@ -1605,6 +1617,7 @@ files:
1605
1617
  - vendor-src/libleptris/test/xsd/libxml2-cases/xsd-list-itemType_0.xsd
1606
1618
  - vendor-src/libleptris/test/xsd/libxml2-cases/xsd-simpleType-varieties_0.xml
1607
1619
  - vendor-src/libleptris/test/xsd/libxml2-cases/xsd-simpleType-varieties_0.xsd
1620
+ - vendor-src/libleptris/test/xsd/test_i1957_1958.cpp
1608
1621
  - vendor-src/libleptris/test/xsd/test_rs35_regression.cpp
1609
1622
  - vendor-src/libleptris/test/xsd/test_xsd_compile.cpp
1610
1623
  - vendor-src/libleptris/test/xsd/xsd-dispositions/README.md