leptris 1.9.407.0 → 1.9.409.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 (34) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/lib/leptris/vendor/aarch64-linux/libleptris.so +0 -0
  4. data/lib/leptris/vendor/aarch64-linux-musl/libleptris.so +0 -0
  5. data/lib/leptris/vendor/arm-linux/libleptris.so +0 -0
  6. data/lib/leptris/vendor/arm-linux-musl/libleptris.so +0 -0
  7. data/lib/leptris/vendor/arm64-darwin/libleptris.dylib +0 -0
  8. data/lib/leptris/vendor/ppc64le-linux/libleptris.so +0 -0
  9. data/lib/leptris/vendor/s390x-linux-musl/libleptris.so +0 -0
  10. data/lib/leptris/vendor/x86_64-darwin/libleptris.dylib +0 -0
  11. data/lib/leptris/vendor/x86_64-linux/libleptris.so +0 -0
  12. data/lib/leptris/vendor/x86_64-linux-musl/libleptris.so +0 -0
  13. data/lib/leptris/version.rb +1 -1
  14. data/vendor-src/README.md +1 -1
  15. data/vendor-src/libleptris/CHANGELOG.md +18 -0
  16. data/vendor-src/libleptris/CMakeLists.txt +1 -1
  17. data/vendor-src/libleptris/src/leptris/descriptor/plan.c +63 -12
  18. data/vendor-src/libleptris/src/leptris/xsd/compile.c +104 -10
  19. data/vendor-src/libleptris/src/leptris/xsd/content_model.c +43 -10
  20. data/vendor-src/libleptris/src/leptris/xsd/validate.c +135 -9
  21. data/vendor-src/libleptris/src/leptris/xsd/xsd_internal.h +8 -0
  22. data/vendor-src/libleptris/test/abi/test_descriptor.cpp +99 -0
  23. data/vendor-src/libleptris/test/xsd/libxml2-cases/attgD019-set/attgD019.xsd +23 -0
  24. data/vendor-src/libleptris/test/xsd/libxml2-cases/attgD019-set/attgD019a.xsd +4 -0
  25. data/vendor-src/libleptris/test/xsd/libxml2-cases/elemZ020-subst-ns/elemZ020.xml +8 -0
  26. data/vendor-src/libleptris/test/xsd/libxml2-cases/elemZ020-subst-ns/elemZ020.xsd +19 -0
  27. data/vendor-src/libleptris/test/xsd/libxml2-cases/stE-union-fixed/stE050.xml +1 -0
  28. data/vendor-src/libleptris/test/xsd/libxml2-cases/stE-union-fixed/stE050.xsd +7 -0
  29. data/vendor-src/libleptris/test/xsd/libxml2-cases/stE-union-fixed/stE055.xml +1 -0
  30. data/vendor-src/libleptris/test/xsd/libxml2-cases/stE-union-fixed/stE055.xsd +7 -0
  31. data/vendor-src/libleptris/test/xsd/test_i1957_1958.cpp +89 -0
  32. data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +73 -0
  33. data/vendor-src/libleptris/vcpkg.json +1 -1
  34. metadata +9 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf13a6b2ea5da2f34da2b3920a7fd4bca9b0f4eb799d3ca77733955fa48c3b8c
4
- data.tar.gz: 8cca358f850c42120a908feb04bedf41b0ae4d1015bdadf78c68f0bc90d00a6d
3
+ metadata.gz: 34d9213388bba418d224f6640d254c359b986b575938949697cf4c8017ae3b34
4
+ data.tar.gz: e5dffe2cb83ea3aaab4da6d4147ebbce456d3032aa5fab6a2aede0b24237172f
5
5
  SHA512:
6
- metadata.gz: 2239efd0a7fd8c7991e826874253b799db4d194abfeb4780fcd424ff2b752fafdfc916e2f2b371e5522ff2b753f195864f2d1129d4668d86a00439af8c5803c9
7
- data.tar.gz: a1f1f8cf2da62b1cb688dd8b18ce0032f23755124e99d1c0cdfaa2148f848a0f7e56bf22b76127d7d67042d3dbcaece102a8ebfa4ec5c713b1e82f31efe996e0
6
+ metadata.gz: 02b97b55c8250a22cfa04425cd9acb0376d99946734f3128c02ec1ff21af15aef4d979d6420f9bbccf0d9eac89e2a622764b8d7b2953f7e2b75714c2fbc9a7a5
7
+ data.tar.gz: 337d18883b91a09d388efe40b65ec153bb38df9303bfe5cfeccacabc7e5b3095582c23c6c33a8d8b8758b114f7bef076231ee5f49ca9b96675eff43f7cd95d2c
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.407"
11
+ LIBLEPTRIS_VERSION = "1.9.409"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leptris
4
- VERSION = "1.9.407.0"
4
+ VERSION = "1.9.409.0"
5
5
  end
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.407
4
+ - libleptris v1.9.409
5
5
  - utf8proc v2.11.0
6
6
 
7
7
  Rebuild by hand:
@@ -1,5 +1,23 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.9.409] - 2026-11-05
4
+
5
+ ### Fixed
6
+
7
+ - **xsd**: particle typing is NAMESPACE-AWARE — content-model capture records particle namespaces (ref-form resolves the QName; name-form reads @form/elementFormDefault), substitution members ride their own namespace (not the head particle's), and the gates are asymmetric per the pinned corpus posture: qualified particles admit no-ns children leniently, unqualified particles are strict with a fallback when no global declaration could type the child (leptris-rs#46; W3C elemZ020 vendored). Rounds out the v1.9.408 XSD wave (rs#45, #1969, #1964).
8
+
9
+
10
+
11
+ ## [1.9.408] - 2026-11-05
12
+
13
+ ### Fixed
14
+
15
+ - emit default-xmlns declarations for prefix-less EXACT rows (#1969) (descriptor)
16
+ - the union value-space fix + default-xmlns emission (leptris-rs#45, leptris#1969) (engine)
17
+ - union-typed fixed constraints compare in the value space (leptris-rs#45) (xsd)
18
+
19
+
20
+
3
21
  ## [1.9.407] - 2026-11-05
4
22
 
5
23
  ### Fixed
@@ -3,7 +3,7 @@
3
3
  cmake_minimum_required(VERSION 3.20)
4
4
 
5
5
  project(leptris
6
- VERSION 1.9.407
6
+ VERSION 1.9.409
7
7
  DESCRIPTION "Fast XML parser and XPath evaluator in pure C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -1525,7 +1525,8 @@ static char* dp_wrapper_name(const struct leptris_plan_result* v) {
1525
1525
 
1526
1526
  static int dp_emit_element_open(const struct leptris_plan_result* v,
1527
1527
  const char* name, dp_sb* b,
1528
- const dp_decls* decls, int is_root) {
1528
+ const dp_decls* decls, int is_root,
1529
+ const char* default_claim) {
1529
1530
  if (!dp_sb_putn(b, "<", 1) || !dp_sb_puts(b, name)) return 0;
1530
1531
  if (is_root && decls) {
1531
1532
  for (size_t i = 0; i < decls->n; i++) {
@@ -1535,6 +1536,17 @@ static int dp_emit_element_open(const struct leptris_plan_result* v,
1535
1536
  return 0;
1536
1537
  }
1537
1538
  }
1539
+ /* leptris#1969: a prefix-less EXACT binding is the DEFAULT
1540
+ * namespace — emit the bare local name and declare xmlns="uri"
1541
+ * when the claim differs from the in-scope default (the root
1542
+ * hoists it once; deeper same-uri nodes inherit). Attribute
1543
+ * rows never take this form (W3C: attributes cannot
1544
+ * default-bind). */
1545
+ if (default_claim) {
1546
+ if (!dp_sb_puts(b, " xmlns=\"") ||
1547
+ !dp_sb_puts(b, default_claim) || !dp_sb_putn(b, "\"", 1))
1548
+ return 0;
1549
+ }
1538
1550
  for (size_t a = 0; a < v->attr_count; a++) {
1539
1551
  /* leptris#1941: a row with an emission binding spells
1540
1552
  * "prefix:local" (dp_wrapper_name's element contract);
@@ -1584,14 +1596,17 @@ static int dp_sb_indent_newline(dp_sb* b, const dp_fmt* fmt, int depth) {
1584
1596
  static int dp_emit_value(const struct leptris_plan_result* v,
1585
1597
  const dp_plan* container, const LeptrisPlan pool,
1586
1598
  dp_sb* b, const dp_decls* decls, int is_root,
1587
- const dp_fmt* fmt, int depth);
1599
+ const dp_fmt* fmt, int depth,
1600
+ const char* cur_default);
1588
1601
 
1589
1602
  static int dp_emit_element(const struct leptris_plan_result* v,
1590
1603
  const char* name, const LeptrisPlan pool,
1591
1604
  const dp_plan* kids_container, dp_sb* b,
1592
1605
  const dp_decls* decls, int is_root,
1593
- const dp_fmt* fmt, int depth) {
1594
- if (!dp_emit_element_open(v, name, b, decls, is_root)) return 0;
1606
+ const dp_fmt* fmt, int depth,
1607
+ const char* cur_default) {
1608
+ if (!dp_emit_element_open(v, name, b, decls, is_root, cur_default))
1609
+ return 0;
1595
1610
  const struct leptris_plan_result** kids = NULL;
1596
1611
  size_t nk = 0, cap = 0;
1597
1612
  if (!dp_flatten_kids(v, &kids, &nk, &cap)) {
@@ -1616,6 +1631,10 @@ static int dp_emit_element(const struct leptris_plan_result* v,
1616
1631
  * parent), so a nested member resolved its kids' rows against
1617
1632
  * the parent's rows and a CONTENT row serialized as an
1618
1633
  * empty-named wrapper. */
1634
+ /* leptris#1969: this element's own claim sets the kids'
1635
+ * in-scope default (a default-xmlns re-declaration nests). */
1636
+ const char* kid_default = cur_default;
1637
+ if (v->ns_uri && !v->ns_prefix) kid_default = v->ns_uri;
1619
1638
  int ok = 1;
1620
1639
  for (size_t i = 0; i < nk && ok; i++) {
1621
1640
  if (indent_kids && !dp_sb_indent_newline(b, fmt, depth + 1)) {
@@ -1623,7 +1642,8 @@ static int dp_emit_element(const struct leptris_plan_result* v,
1623
1642
  break;
1624
1643
  }
1625
1644
  ok = dp_emit_value(kids[i], kids_container, pool, b, NULL, 0,
1626
- fmt, indent_kids ? depth + 1 : depth);
1645
+ fmt, indent_kids ? depth + 1 : depth,
1646
+ kid_default);
1627
1647
  }
1628
1648
  free((void*)kids);
1629
1649
  if (!ok) return 0;
@@ -1638,7 +1658,8 @@ static int dp_emit_element(const struct leptris_plan_result* v,
1638
1658
  static int dp_emit_value(const struct leptris_plan_result* v,
1639
1659
  const dp_plan* container, const LeptrisPlan pool,
1640
1660
  dp_sb* b, const dp_decls* decls, int is_root,
1641
- const dp_fmt* fmt, int depth) {
1661
+ const dp_fmt* fmt, int depth,
1662
+ const char* cur_default) {
1642
1663
  if (v->kind == LEPTRIS_PLAN_VALUE_RAW)
1643
1664
  return dp_sb_puts(b, v->str ? v->str : "");
1644
1665
  if (v->kind == LEPTRIS_PLAN_VALUE_ELEMENT) {
@@ -1688,8 +1709,17 @@ static int dp_emit_value(const struct leptris_plan_result* v,
1688
1709
  kids_container =
1689
1710
  &poolp->plans[cap->child_plan_index];
1690
1711
  }
1712
+ /* leptris#1969: this node's default-xmlns claim (a ns_uri
1713
+ * without a prefix). Emitted only when it differs from the
1714
+ * in-scope default; the kids inherit the claim. */
1715
+ const char* claim =
1716
+ (v->ns_uri && !v->ns_prefix) ? v->ns_uri : NULL;
1717
+ const char* open_claim =
1718
+ (claim && (!cur_default || strcmp(claim, cur_default) != 0))
1719
+ ? claim
1720
+ : NULL;
1691
1721
  int ok = dp_emit_element(v, name, pool, kids_container, b,
1692
- decls, is_root, fmt, depth);
1722
+ decls, is_root, fmt, depth, open_claim);
1693
1723
  free(name);
1694
1724
  return ok;
1695
1725
  }
@@ -1703,7 +1733,16 @@ static int dp_emit_value(const struct leptris_plan_result* v,
1703
1733
  /* The row is the wrapper element around this text. */
1704
1734
  char* name = dp_wrapper_name(v);
1705
1735
  if (!name) return 0;
1736
+ /* leptris#1969: the wrapper's own default-xmlns claim. */
1737
+ const char* wclaim =
1738
+ (v->ns_uri && !v->ns_prefix &&
1739
+ (!cur_default || strcmp(v->ns_uri, cur_default) != 0))
1740
+ ? v->ns_uri
1741
+ : NULL;
1706
1742
  int ok = dp_sb_putn(b, "<", 1) && dp_sb_puts(b, name) &&
1743
+ (wclaim ? dp_sb_puts(b, " xmlns=\"") &&
1744
+ dp_sb_puts(b, wclaim) && dp_sb_putn(b, "\"", 1)
1745
+ : 1) &&
1707
1746
  dp_sb_putn(b, ">", 1) && dp_sb_escape(b, text, 0) &&
1708
1747
  dp_sb_puts(b, "</") && dp_sb_puts(b, name) &&
1709
1748
  dp_sb_putn(b, ">", 1);
@@ -1732,7 +1771,7 @@ static char* dp_serialize_impl(LeptrisPlan plan,
1732
1771
  }
1733
1772
  dp_sb b = {0};
1734
1773
  int ok = dp_emit_value(rv, NULL, (const LeptrisPlan)plan, &b,
1735
- &decls, 1, fmt, 0);
1774
+ &decls, 1, fmt, 0, NULL);
1736
1775
  dp_decls_free(&decls);
1737
1776
  if (!ok) {
1738
1777
  free(b.s);
@@ -1997,18 +2036,23 @@ static struct leptris_plan_result* plan_result_build_windowed(
1997
2036
  } else if (cr->child_plan_index >= 0 &&
1998
2037
  cr->child_plan_index <
1999
2038
  (int32_t)pool->plan_count &&
2000
- pool->plans[cr->child_plan_index].ns_prefix &&
2039
+ pool->plans[cr->child_plan_index].ns_uri &&
2001
2040
  pool->plans[cr->child_plan_index].ns_form ==
2002
2041
  LEPTRIS_PLAN_NS_EXACT) {
2003
2042
  ns_src = &pool->plans[cr->child_plan_index];
2004
- } else if (cp->ns_prefix &&
2043
+ } else if (cp->ns_uri &&
2005
2044
  cp->ns_form == LEPTRIS_PLAN_NS_EXACT) {
2006
2045
  ns_src = cp;
2007
2046
  }
2008
2047
  if (ns_src) {
2009
- v->ns_prefix = dp_strdup(ns_src->ns_prefix);
2048
+ /* leptris#1969: ns_prefix NULL + ns_uri set is
2049
+ * the DEFAULT-xmlns claim (bare local name,
2050
+ * xmlns="uri" hoisted on the emitting root). */
2051
+ v->ns_prefix = ns_src->ns_prefix
2052
+ ? dp_strdup(ns_src->ns_prefix)
2053
+ : NULL;
2010
2054
  v->ns_uri = dp_strdup(ns_src->ns_uri);
2011
- if (!v->ns_prefix || !v->ns_uri) goto oom;
2055
+ if (!v->ns_uri) goto oom;
2012
2056
  }
2013
2057
  } else if (cp->ns_prefix &&
2014
2058
  cp->ns_form == LEPTRIS_PLAN_NS_EXACT) {
@@ -2017,6 +2061,13 @@ static struct leptris_plan_result* plan_result_build_windowed(
2017
2061
  v->ns_prefix = dp_strdup(cp->ns_prefix);
2018
2062
  v->ns_uri = dp_strdup(cp->ns_uri);
2019
2063
  if (!v->ns_prefix || !v->ns_uri) goto oom;
2064
+ } else if (cp->ns_uri &&
2065
+ cp->ns_form == LEPTRIS_PLAN_NS_EXACT) {
2066
+ /* leptris#1969: the root op binds the plan's own
2067
+ * DEFAULT namespace (prefix-less EXACT) —
2068
+ * xmlns="uri" hoists on the output root. */
2069
+ v->ns_uri = dp_strdup(cp->ns_uri);
2070
+ if (!v->ns_uri) goto oom;
2020
2071
  }
2021
2072
  if (sp == 0) {
2022
2073
  if (root) {
@@ -125,7 +125,12 @@ static XsdAssert* xsd_capture_assert(struct leptris_xsd_schema* s,
125
125
  LeptrisElement e);
126
126
  static XsdCm* xsd_capture_any(LeptrisElement any_child);
127
127
  static char* xsd_capture_unit_tns(LeptrisElement e);
128
+ static void xsd_resolve_qname(LeptrisElement e, const char* qname,
129
+ char* uri, size_t urisz, char* local,
130
+ size_t localsz);
128
131
  static char* xsd_capture_any_attr_ns(LeptrisElement container);
132
+ static char* xsd_capture_any_attr_ns_deep(
133
+ struct leptris_xsd_schema* s, LeptrisElement container, int depth);
129
134
  static char* xsd_capture_any_attr_not_qname(LeptrisElement container);
130
135
 
131
136
  /* #1626: prefixed QName refs (type="w:CT_Border") resolve by local
@@ -270,11 +275,57 @@ static XsdCm* xsd_cm_parse(struct leptris_xsd_schema* s,
270
275
  } else if (strcmp(local, "element") == 0) {
271
276
  cm = xsd_cm_new(XSD_CM_ELEMENT);
272
277
  if (cm) {
273
- const char* nm =
274
- leptris_element_attribute(e, "name");
275
- if (!nm)
276
- nm = xsd_local_name(
277
- leptris_element_attribute(e, "ref"));
278
+ const char* ref_raw =
279
+ leptris_element_attribute(e, "ref");
280
+ const char* nm = NULL;
281
+ if (ref_raw) {
282
+ /* elemZ020: record the particle's namespace — a
283
+ * ref binds in the REFERENCED DECLARATION's ns
284
+ * (same-tns ref → tns, cross-ns → the foreign
285
+ * ns). The old capture kept the local name only,
286
+ * so the NFA and the typing DFS matched by name
287
+ * alone. */
288
+ nm = xsd_local_name(ref_raw);
289
+ char ruri[512], rlocal[256];
290
+ xsd_resolve_qname(e, ref_raw, ruri, sizeof(ruri),
291
+ rlocal, sizeof(rlocal));
292
+ if (ruri[0])
293
+ cm->ns = xsd_strdup(ruri);
294
+ else
295
+ cm->ns = xsd_capture_unit_tns(e);
296
+ } else {
297
+ nm = leptris_element_attribute(e, "name");
298
+ /* name-form: @form wins; otherwise the unit's
299
+ * elementFormDefault decides */
300
+ const char* form =
301
+ leptris_element_attribute(e, "form");
302
+ const char* efd = NULL;
303
+ if (!form) {
304
+ for (LeptrisElement up =
305
+ leptris_element_parent(e);
306
+ up; up = leptris_element_parent(up)) {
307
+ const char* ul = NULL;
308
+ leptris_element_expanded_name(
309
+ up, &ul, NULL, NULL);
310
+ if (ul && strcmp(ul, "schema") == 0) {
311
+ efd = leptris_element_attribute(
312
+ up, "elementFormDefault");
313
+ break;
314
+ }
315
+ }
316
+ }
317
+ int qualified =
318
+ form ? strcmp(form, "qualified") == 0
319
+ : (efd &&
320
+ strcmp(efd, "qualified") == 0);
321
+ if (qualified) {
322
+ char* tns = xsd_capture_unit_tns(e);
323
+ if (tns && tns[0])
324
+ cm->ns = tns;
325
+ else
326
+ free(tns);
327
+ }
328
+ }
278
329
  cm->name = xsd_strdup(nm);
279
330
  const char* pty =
280
331
  leptris_element_attribute(e, "type");
@@ -3293,7 +3344,8 @@ static XsdCm* xsd_capture_complex_model(struct leptris_xsd_schema* s,
3293
3344
  if (!attrs) attrs = xsd_capture_attr_rows(s, ct, 0);
3294
3345
  if (!any_attr_unit_ns)
3295
3346
  any_attr_unit_ns = xsd_capture_unit_tns(ct);
3296
- if (!any_attr_ns) any_attr_ns = xsd_capture_any_attr_ns(ct);
3347
+ if (!any_attr_ns)
3348
+ any_attr_ns = xsd_capture_any_attr_ns_deep(s, ct, 0);
3297
3349
  if (!any_attr_not_qname)
3298
3350
  any_attr_not_qname = xsd_capture_any_attr_not_qname(ct);
3299
3351
  }
@@ -3376,14 +3428,19 @@ static const XsdElementDecl* xsd_find_element_decl(
3376
3428
  return NULL;
3377
3429
  }
3378
3430
 
3379
- int xsd_is_substitute(struct leptris_xsd_schema* s,
3380
- const char* name, const char* head) {
3431
+ const XsdElementDecl* xsd_substitute_member(
3432
+ struct leptris_xsd_schema* s, const char* name, const char* head) {
3381
3433
  const XsdElementDecl* d = xsd_find_element_decl(s, name);
3382
3434
  for (int hops = 0; d && d->sub_head && hops < 16; hops++) {
3383
- if (strcmp(d->sub_head, head) == 0) return 1;
3435
+ if (strcmp(d->sub_head, head) == 0) return d;
3384
3436
  d = xsd_find_element_decl(s, d->sub_head);
3385
3437
  }
3386
- return 0;
3438
+ return NULL;
3439
+ }
3440
+
3441
+ int xsd_is_substitute(struct leptris_xsd_schema* s,
3442
+ const char* name, const char* head) {
3443
+ return xsd_substitute_member(s, name, head) != NULL;
3387
3444
  }
3388
3445
 
3389
3446
  int xsd_schema_version_11(struct leptris_xsd_schema* s) {
@@ -3623,6 +3680,43 @@ static char* xsd_capture_unit_tns(LeptrisElement e) {
3623
3680
  return NULL;
3624
3681
  }
3625
3682
 
3683
+ /* leptris#1964: the anyAttribute grammar rides attributeGroup
3684
+ * refs too — attgD019's wildcard lives inside the referenced
3685
+ * group, not the complexType's direct children. Follows refs
3686
+ * (depth-bounded); the group's OWN element is the walk root. */
3687
+ static char* xsd_capture_any_attr_ns_deep(
3688
+ struct leptris_xsd_schema* s, LeptrisElement container,
3689
+ int depth) {
3690
+ if (depth > 8) return NULL;
3691
+ for (LeptrisNodeRef ac = leptris_node_first_child(
3692
+ leptris_element_as_node(container));
3693
+ ac; ac = leptris_node_next_sibling(ac)) {
3694
+ if (leptris_node_get_type(ac) != LEPTRIS_NODE_TYPE_ELEMENT)
3695
+ continue;
3696
+ LeptrisElement ae = (LeptrisElement)ac;
3697
+ const char* al = NULL, *au = NULL;
3698
+ leptris_element_expanded_name(ae, &al, NULL, &au);
3699
+ if (!al || (au && strcmp(au, XSD_NS) != 0)) continue;
3700
+ if (strcmp(al, "anyAttribute") == 0)
3701
+ return xsd_strdup(
3702
+ leptris_element_attribute(ae, "namespace"));
3703
+ if (strcmp(al, "attributeGroup") == 0) {
3704
+ const char* ref = xsd_local_name(
3705
+ leptris_element_attribute(ae, "ref"));
3706
+ if (!ref) continue;
3707
+ XsdAttrGroupDef* g = s->attr_groups;
3708
+ for (; g; g = g->next)
3709
+ if (strcmp(g->name, ref) == 0) break;
3710
+ if (g && g->elem) {
3711
+ char* r = xsd_capture_any_attr_ns_deep(s, g->elem,
3712
+ depth + 1);
3713
+ if (r) return r;
3714
+ }
3715
+ }
3716
+ }
3717
+ return NULL;
3718
+ }
3719
+
3626
3720
  static char* xsd_capture_any_attr_ns(LeptrisElement container) {
3627
3721
  for (LeptrisNodeRef ac = leptris_node_first_child(
3628
3722
  leptris_element_as_node(container));
@@ -15,6 +15,13 @@
15
15
 
16
16
  #include "xsd_internal.h"
17
17
 
18
+ /* validate.c-facing global lookup (compile.c): an unqualified
19
+ * particle may leniently admit a namespaced child only when no
20
+ * global declaration in the child's namespace could type it
21
+ * (elemZ020 vs the OOXML-style wp.xsd corpus). */
22
+ extern const struct xsd_element_decl* xsd_find_element_child_ns(
23
+ struct leptris_xsd_schema* s, const char* name, const char* uri);
24
+
18
25
  typedef struct {
19
26
  int from;
20
27
  int symbol; /* -1 = epsilon; else a particle transition */
@@ -345,8 +352,11 @@ static int all_root_valid(XsdCm* all, const char* target_ns,
345
352
  size_t hits = 0;
346
353
  for (size_t i = 0; i < count; i++) {
347
354
  const char* uri = ns_uris ? ns_uris[i] : NULL;
348
- if (p->name && strcmp(p->name, names[i]) == 0 &&
349
- (!p->ns || (uri && strcmp(uri, p->ns) == 0)))
355
+ int child_qualified = uri && uri[0];
356
+ int ns_ok = p->ns ? (!child_qualified ||
357
+ strcmp(uri, p->ns) == 0)
358
+ : !child_qualified;
359
+ if (p->name && strcmp(p->name, names[i]) == 0 && ns_ok)
350
360
  hits++;
351
361
  }
352
362
  if ((long)hits < p->min) return 0;
@@ -357,8 +367,11 @@ static int all_root_valid(XsdCm* all, const char* target_ns,
357
367
  int matched = 0;
358
368
  const char* uri = ns_uris ? ns_uris[i] : NULL;
359
369
  for (XsdCm* p = all->first_child; p && !matched; p = p->next) {
360
- if (p->name && strcmp(p->name, names[i]) == 0 &&
361
- (!p->ns || (uri && strcmp(uri, p->ns) == 0)))
370
+ int child_qualified2 = uri && uri[0];
371
+ int ns_ok2 = p->ns ? (!child_qualified2 ||
372
+ strcmp(uri, p->ns) == 0)
373
+ : !child_qualified2;
374
+ if (p->name && strcmp(p->name, names[i]) == 0 && ns_ok2)
362
375
  matched = 1;
363
376
  }
364
377
  if (!matched) return 0;
@@ -408,12 +421,32 @@ int xsd_content_valid(struct leptris_xsd_schema* s, XsdCm* model,
408
421
  continue;
409
422
  XsdCm* p = tr->particle;
410
423
  if (p->kind == XSD_CM_ELEMENT) {
411
- int named = (strcmp(p->name, names[c]) == 0) ||
412
- (n.s && xsd_is_substitute(
413
- n.s, names[c], p->name));
414
- if (named &&
415
- (!p->ns || (uri && strcmp(uri, p->ns) == 0)))
416
- ss_add(&next, tr->to);
424
+ /* elemZ020: the ns gate is asymmetric — a
425
+ * qualified particle matches its own ns but
426
+ * leniently admits a no-ns child (the pinned
427
+ * #1871 corpus posture); an unqualified
428
+ * particle (ns NULL) is strict: no-ns children
429
+ * only. A substitute hit rides the MEMBER's
430
+ * own ns (cross-ns groups, #1881 sets). */
431
+ const char* pns = p->ns;
432
+ int named = (strcmp(p->name, names[c]) == 0);
433
+ if (!named && n.s) {
434
+ const XsdElementDecl* m =
435
+ xsd_substitute_member(n.s, names[c],
436
+ p->name);
437
+ if (m) {
438
+ named = 1;
439
+ if (m->ns) pns = m->ns;
440
+ }
441
+ }
442
+ int child_ns = uri && uri[0];
443
+ int pns_ok =
444
+ pns ? (!child_ns ||
445
+ (uri && strcmp(uri, pns) == 0))
446
+ : (!child_ns ||
447
+ (n.s && !xsd_find_element_child_ns(
448
+ n.s, names[c], uri)));
449
+ if (named && pns_ok) ss_add(&next, tr->to);
417
450
  } else if (p->kind == XSD_CM_ANY) {
418
451
  /* #1735: ##targetNamespace/##other are relative
419
452
  * to the DECLARING unit's tns */
@@ -301,6 +301,88 @@ static int text_valid(struct xsd_validator* v,
301
301
  static void validate_element(struct xsd_validator* v,
302
302
  struct leptris_xsd_schema* s,
303
303
  LeptrisElement elem, int depth);
304
+ static void xsd_member_canon(const char* mname, char* out, size_t cap) {
305
+ const char* local = mname ? strchr(mname, ':') : NULL;
306
+ local = local ? local + 1 : mname;
307
+ snprintf(out, cap, "xs:%s", local ? local : "");
308
+ }
309
+
310
+ /* Value-space equality within one union member: numerics compare
311
+ * numerically ("1.0" == "1.000"), booleans identify across the
312
+ * {true,1}/{false,0} spellings, everything else is exact text. */
313
+ static int xsd_value_equal(const char* canon_type, const char* a,
314
+ const char* b) {
315
+ if (strcmp(a, b) == 0) return 1;
316
+ if (strcmp(canon_type, "xs:boolean") == 0) {
317
+ int av = strcmp(a, "true") == 0 || strcmp(a, "1") == 0;
318
+ int bv = strcmp(b, "true") == 0 || strcmp(b, "1") == 0;
319
+ return av == bv;
320
+ }
321
+ if (strcmp(canon_type, "xs:float") == 0 ||
322
+ strcmp(canon_type, "xs:double") == 0)
323
+ return strtod(a, NULL) == strtod(b, NULL);
324
+ if (strstr(canon_type, "int") || strstr(canon_type, "decimal") ||
325
+ strstr(canon_type, "long") || strstr(canon_type, "short") ||
326
+ strstr(canon_type, "byte") ||
327
+ strstr(canon_type, "Negative") || strstr(canon_type, "positive"))
328
+ return strtod(a, NULL) == strtod(b, NULL);
329
+ return 0;
330
+ }
331
+
332
+ /* leptris-rs#45 (stE050/stE055): union-typed fixed constraints
333
+ * compare in the VALUE SPACE of the first union member that
334
+ * validates each lexical form — fixed "1" and instance "true"
335
+ * both validate as xs:boolean (its lexical space accepts "1");
336
+ * "1.0" and "1.000" both as xs:float. Raw strcmp wrongly
337
+ * rejected value-equal forms. Returns 1 when a single member
338
+ * type validates both the fixed value and the instance text. */
339
+ static int xsd_union_fixed_match(struct leptris_xsd_schema* s,
340
+ const XsdSimple* ut, const char* ns,
341
+ const char* fixed, const char* text) {
342
+ if (!ut || ut->deriv != XSD_SIMPLE_UNION) return 0;
343
+ size_t n = ut->member_count > ut->member_def_count
344
+ ? ut->member_count
345
+ : ut->member_def_count;
346
+ int fixed_member = -1;
347
+ for (size_t i = 0; i < n && fixed_member < 0; i++) {
348
+ const XsdSimple* def =
349
+ i < ut->member_def_count ? ut->member_defs[i] : NULL;
350
+ const char* mname = i < ut->member_count ? ut->members[i] : NULL;
351
+ int ok;
352
+ char canon[128];
353
+ if (mname) xsd_member_canon(mname, canon, sizeof(canon));
354
+ if (def) {
355
+ ok = xsd_simple_valid_chain(s, def, fixed);
356
+ } else if (mname && strncmp(canon, "xs:", 3) == 0) {
357
+ ok = xsd_builtin_valid(canon, fixed);
358
+ } else if (mname) {
359
+ const XsdSimple* m = xsd_find_simple_ns_pub(s, canon, ns);
360
+ ok = m && xsd_simple_valid_chain(s, m, fixed);
361
+ } else {
362
+ continue;
363
+ }
364
+ if (ok) fixed_member = (int)i;
365
+ }
366
+ if (fixed_member < 0) return 0;
367
+ const XsdSimple* def =
368
+ (size_t)fixed_member < ut->member_def_count
369
+ ? ut->member_defs[fixed_member]
370
+ : NULL;
371
+ if (def) return xsd_simple_valid_chain(s, def, text) &&
372
+ xsd_value_equal("xs:string", fixed, text);
373
+ const char* mname = (size_t)fixed_member < ut->member_count
374
+ ? ut->members[fixed_member]
375
+ : NULL;
376
+ if (!mname) return 0;
377
+ char canon[128];
378
+ xsd_member_canon(mname, canon, sizeof(canon));
379
+ if (strncmp(canon, "xs:", 3) == 0)
380
+ return xsd_builtin_valid(canon, text) &&
381
+ xsd_value_equal(canon, fixed, text);
382
+ const XsdSimple* m = xsd_find_simple_ns_pub(s, canon, ns);
383
+ return m && xsd_simple_valid_chain(s, m, text);
384
+ }
385
+
304
386
  static void validate_element_decl(struct xsd_validator* v,
305
387
  struct leptris_xsd_schema* s,
306
388
  LeptrisElement elem, int depth,
@@ -517,6 +599,14 @@ static void validate_children(struct xsd_validator* v,
517
599
  if (wpc == 2) continue;
518
600
  const char* ptype = NULL;
519
601
  const char* pfill = NULL;
602
+ /* elemZ020 lenient fallback: an unqualified particle may
603
+ * still type a namespaced child when NO global declaration
604
+ * in the child's namespace could (the OOXML-style wp.xsd
605
+ * corpus: no elementFormDefault, no globals). The strict
606
+ * pass remembers the candidate; the global lookup below
607
+ * decides whether it is needed. */
608
+ const char* ltype = NULL;
609
+ const char* lfill = NULL;
520
610
  if (model) {
521
611
  XsdCm* stack[64];
522
612
  int sp = 0;
@@ -524,15 +614,34 @@ static void validate_children(struct xsd_validator* v,
524
614
  while (sp > 0 && ptype == NULL) {
525
615
  XsdCm* p = stack[--sp];
526
616
  for (; p; p = p->next) {
617
+ int child_ns = cu && cu[0];
618
+ /* asymmetric ns gate (elemZ020 + the pinned
619
+ * #1871 lenient posture): qualified particles
620
+ * match their own ns and leniently admit no-ns
621
+ * children; unqualified particles are strict —
622
+ * no-ns children only, with the lenient
623
+ * fallback when nothing else can type it. */
624
+ int pns_ok =
625
+ p->ns ? (!child_ns ||
626
+ strcmp(p->ns, cu) == 0)
627
+ : !child_ns;
527
628
  if (p->kind == XSD_CM_ELEMENT && p->name &&
528
629
  strcmp(p->name, cl) == 0 && p->type) {
529
- ptype = p->type;
530
- /* leptris-rs#35 (isDefault005): the
531
- * particle's fixed/default value satisfies
532
- * EMPTY content (§3.12.2). */
533
- pfill = p->fixed_value ? p->fixed_value
534
- : p->default_value;
535
- break;
630
+ if (pns_ok) {
631
+ ptype = p->type;
632
+ /* leptris-rs#35 (isDefault005): the
633
+ * particle's fixed/default value
634
+ * satisfies EMPTY content (§3.12.2). */
635
+ pfill = p->fixed_value ? p->fixed_value
636
+ : p->default_value;
637
+ break;
638
+ }
639
+ if (!ltype) {
640
+ ltype = p->type;
641
+ lfill = p->fixed_value
642
+ ? p->fixed_value
643
+ : p->default_value;
644
+ }
536
645
  }
537
646
  if (p->kind == XSD_CM_GROUP_REF) {
538
647
  XsdGroupDef* g = xsd_find_group(s, p->name);
@@ -568,7 +677,15 @@ static void validate_children(struct xsd_validator* v,
568
677
  } else {
569
678
  const XsdElementDecl* cd =
570
679
  xsd_find_element_child_ns(s, cl, cu);
571
- if (cd) validate_element_decl(v, s, ce, 0, cd);
680
+ if (cd)
681
+ validate_element_decl(v, s, ce, 0, cd);
682
+ else if (ltype) {
683
+ /* nothing global claims the namespaced child —
684
+ * the unqualified particle's type governs
685
+ * (wp.xsd corpus posture) */
686
+ validate_local(v, s, ce, cl, ltype, lfill,
687
+ ct ? ct->ns : NULL);
688
+ }
572
689
  }
573
690
  /* wildcard-admitted children without a declaration pass:
574
691
  * strict and lax alike admit undeclared names (the pinned
@@ -913,7 +1030,16 @@ static void validate_element_decl(struct xsd_validator* v,
913
1030
  break;
914
1031
  }
915
1032
  if (d->fixed) {
916
- if (has_content && strcmp(text, d->fixed) != 0)
1033
+ int match = !has_content || strcmp(text, d->fixed) == 0;
1034
+ if (!match) {
1035
+ const XsdSimple* ut =
1036
+ d->type ? xsd_find_simple_ns_pub(s, d->type, d->ns)
1037
+ : NULL;
1038
+ if (ut)
1039
+ match = xsd_union_fixed_match(s, ut, d->ns, d->fixed,
1040
+ text);
1041
+ }
1042
+ if (!match)
917
1043
  verrfk(v, "content-model", "element", local,
918
1044
  "content does not match the fixed value");
919
1045
  if (!has_content)
@@ -211,6 +211,14 @@ typedef struct xsd_element_decl {
211
211
  int xsd_is_substitute(struct leptris_xsd_schema* s,
212
212
  const char* name, const char* head);
213
213
 
214
+ /* elemZ020: the MEMBER declaration behind a substitute hit — the
215
+ * member carries its OWN namespace (a member in ns g rides a head
216
+ * particle written for ns f, XSD 1.1 cross-ns groups + schema-set
217
+ * compilation), so ns gates must compare against the member's ns,
218
+ * never the head particle's. */
219
+ const XsdElementDecl* xsd_substitute_member(
220
+ struct leptris_xsd_schema* s, const char* name, const char* head);
221
+
214
222
  typedef struct xsd_attr_decl {
215
223
  char* name; /* attribute local name */
216
224
  char* type; /* builtin ref or local simpleType name (NULL=anySimple) */
@@ -2786,6 +2786,105 @@ TEST(Plan1941, ResultBuildExplicitRowBindingBeatsInheritance) {
2786
2786
  leptris_plan_free(plan);
2787
2787
  }
2788
2788
 
2789
+ // ---- leptris#1969: prefix-less EXACT rows are the DEFAULT xmlns --
2790
+ // ns_form EXACT with ns_uri but NO ns_prefix binds the default
2791
+ // namespace: the element emits a bare local name and hoists
2792
+ // xmlns="uri". The declaration appears once on the output root;
2793
+ // same-uri descendants inherit it (no re-declare); a deeper
2794
+ // different default re-declares. Attribute rows never default-bind
2795
+ // (pinned by the Plan1486 cases — the attr row's ns_prefix gate).
2796
+
2797
+ TEST(Plan1969, ResultBuildEmitsDefaultXmlnsOnRoot) {
2798
+ LeptrisStatus st = LEPTRIS_OK;
2799
+ leptris_child_plan kids[1] = {};
2800
+ kids[0].wire_name = "p";
2801
+ kids[0].kind = LEPTRIS_PLAN_KIND_SCALAR;
2802
+ kids[0].child_plan_index = -1;
2803
+ kids[0].ns_form = LEPTRIS_PLAN_NS_EXACT;
2804
+ kids[0].ns_uri = "urn:w";
2805
+
2806
+ leptris_element_plan plans[1] = {};
2807
+ plans[0].element_name = "document";
2808
+ plans[0].ns_form = LEPTRIS_PLAN_NS_EXACT;
2809
+ plans[0].ns_uri = "urn:w";
2810
+ plans[0].child_count = 1;
2811
+ plans[0].child_plans = kids;
2812
+
2813
+ leptris_plan_spec spec = {};
2814
+ spec.abi_version = leptris_plan_abi_version();
2815
+ spec.plan_count = 1;
2816
+ spec.plans = plans;
2817
+ LeptrisPlan plan = leptris_plan_build(&spec, &st);
2818
+ ASSERT_NE(plan, nullptr);
2819
+
2820
+ leptris_plan_row_op ops[] = {
2821
+ {LEPTRIS_PLAN_OP_ELEMENT, 0, UINT32_MAX, NULL, NULL, 0},
2822
+ {LEPTRIS_PLAN_OP_SCALAR, 0, 0, NULL, "x", 1},
2823
+ {LEPTRIS_PLAN_OP_END, 0, UINT32_MAX, NULL, NULL, 0},
2824
+ };
2825
+ LeptrisPlanResult r = leptris_plan_result_build(plan, ops, 3, &st);
2826
+ ASSERT_NE(r, nullptr);
2827
+ char* out = leptris_plan_serialize(plan, r, &st);
2828
+ ASSERT_NE(out, nullptr);
2829
+ EXPECT_STREQ(out, "<document xmlns=\"urn:w\"><p>x</p></document>");
2830
+ leptris_free_string(out);
2831
+ leptris_plan_result_free(r);
2832
+ leptris_plan_free(plan);
2833
+ }
2834
+
2835
+ TEST(Plan1969, ResultBuildNestedDefaultRedeclaresDifferentUri) {
2836
+ LeptrisStatus st = LEPTRIS_OK;
2837
+ leptris_child_plan a_kids[1] = {};
2838
+ a_kids[0].wire_name = "b";
2839
+ a_kids[0].kind = LEPTRIS_PLAN_KIND_NESTED;
2840
+ a_kids[0].child_plan_index = 1;
2841
+
2842
+ leptris_child_plan b_kids[1] = {};
2843
+ b_kids[0].wire_name = "c";
2844
+ b_kids[0].kind = LEPTRIS_PLAN_KIND_SCALAR;
2845
+ b_kids[0].child_plan_index = -1;
2846
+
2847
+ leptris_element_plan plans[2] = {};
2848
+ plans[0].element_name = "a";
2849
+ plans[0].ns_form = LEPTRIS_PLAN_NS_EXACT;
2850
+ plans[0].ns_uri = "urn:1";
2851
+ plans[0].child_count = 1;
2852
+ plans[0].child_plans = a_kids;
2853
+ plans[1].element_name = "b";
2854
+ plans[1].ns_form = LEPTRIS_PLAN_NS_EXACT;
2855
+ plans[1].ns_uri = "urn:2";
2856
+ plans[1].child_count = 1;
2857
+ plans[1].child_plans = b_kids;
2858
+
2859
+ leptris_plan_spec spec = {};
2860
+ spec.abi_version = leptris_plan_abi_version();
2861
+ spec.plan_count = 2;
2862
+ spec.plans = plans;
2863
+ LeptrisPlan plan = leptris_plan_build(&spec, &st);
2864
+ ASSERT_NE(plan, nullptr);
2865
+
2866
+ leptris_plan_row_op ops[] = {
2867
+ {LEPTRIS_PLAN_OP_ELEMENT, 0, UINT32_MAX, NULL, NULL, 0},
2868
+ {LEPTRIS_PLAN_OP_ELEMENT, 0, 0, NULL, NULL, 0},
2869
+ {LEPTRIS_PLAN_OP_SCALAR, 1, 0, NULL, "x", 1},
2870
+ {LEPTRIS_PLAN_OP_END, 0, UINT32_MAX, NULL, NULL, 0},
2871
+ {LEPTRIS_PLAN_OP_END, 0, UINT32_MAX, NULL, NULL, 0},
2872
+ };
2873
+ LeptrisPlanResult r = leptris_plan_result_build(plan, ops, 5, &st);
2874
+ ASSERT_NE(r, nullptr);
2875
+ char* out = leptris_plan_serialize(plan, r, &st);
2876
+ ASSERT_NE(out, nullptr);
2877
+ /* b's nested row inherits its child plan's DEFAULT binding —
2878
+ * urn:2 differs from the in-scope urn:1, so b re-declares; c
2879
+ * inherits urn:2 and spells bare. */
2880
+ EXPECT_STREQ(out,
2881
+ "<a xmlns=\"urn:1\"><b xmlns=\"urn:2\">"
2882
+ "<c>x</c></b></a>");
2883
+ leptris_free_string(out);
2884
+ leptris_plan_result_free(r);
2885
+ leptris_plan_free(plan);
2886
+ }
2887
+
2789
2888
  TEST(Plan408, ResultBuildRejectsBadPrograms) {
2790
2889
  LeptrisStatus st = LEPTRIS_OK;
2791
2890
  leptris_element_plan plans[1] = {};
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0"?>
2
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified">
3
+ <xsd:attribute name="foo" type="xsd:string"/>
4
+ <xsd:attribute name="bar" type="xsd:string"/>
5
+ <xsd:attributeGroup name="attG" id="abc" xmlns:foo="foo" foo:anyattribute="foo">
6
+ <xsd:attribute name="att1" type="xsd:int"/>
7
+ <xsd:anyAttribute namespace="##any" id="anyAtt">
8
+ <xsd:annotation>
9
+ <xsd:documentation> testing </xsd:documentation>
10
+ </xsd:annotation>
11
+ </xsd:anyAttribute>
12
+ </xsd:attributeGroup>
13
+ <xsd:complexType name="attgRef">
14
+ <xsd:attributeGroup ref="attG"/>
15
+ </xsd:complexType>
16
+ <xsd:element name="doc">
17
+ <xsd:complexType>
18
+ <xsd:choice maxOccurs="10">
19
+ <xsd:element name="elem" type="attgRef"/>
20
+ </xsd:choice>
21
+ </xsd:complexType>
22
+ </xsd:element>
23
+ </xsd:schema>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0"?>
2
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="foo">
3
+ <xsd:attribute name="foo" type="xsd:string"/>
4
+ </xsd:schema>
@@ -0,0 +1,8 @@
1
+ <foo:root
2
+ xmlns:foo="foo"
3
+ >
4
+ <foo:foo>true</foo:foo>
5
+ <foo>123</foo >
6
+ <foo:foo>true</foo:foo>
7
+ <foo>123</foo >
8
+ </foo:root>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0"?>
2
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3
+ elementFormDefault="qualified"
4
+ targetNamespace="foo"
5
+ xmlns="foo"
6
+ >
7
+ <xsd:element name="e1" type="xsd:boolean" />
8
+ <xsd:element name="foo" substitutionGroup="e1" type="xsd:boolean" />
9
+
10
+ <xsd:element name="root" type="B" />
11
+
12
+ <xsd:complexType name="B">
13
+ <xsd:choice maxOccurs="1000">
14
+ <xsd:element ref="e1" />
15
+ <xsd:element name="foo" type="xsd:int" form="unqualified"/>
16
+ </xsd:choice>
17
+ </xsd:complexType>
18
+
19
+ </xsd:schema>
@@ -0,0 +1,7 @@
1
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
+ <xsd:element name="root" fixed="1">
3
+ <xsd:simpleType>
4
+ <xsd:union memberTypes="xsd:boolean xsd:int xsd:string"/>
5
+ </xsd:simpleType>
6
+ </xsd:element>
7
+ </xsd:schema>
@@ -0,0 +1,7 @@
1
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
+ <xsd:element name="root" fixed="1.0">
3
+ <xsd:simpleType>
4
+ <xsd:union memberTypes="xsd:boolean xsd:float xsd:double xsd:normalizedString"/>
5
+ </xsd:simpleType>
6
+ </xsd:element>
7
+ </xsd:schema>
@@ -88,3 +88,92 @@ TEST(I1958, RedefinedSimpleTypeFacetEnforced) {
88
88
  leptris_document_free(d);
89
89
  leptris_xsd_free(s);
90
90
  }
91
+
92
+
93
+ // ---- leptris-rs#45: union-typed fixed constraints compare in the
94
+ // union's VALUE SPACE — the first member type validating the fixed
95
+ // lexical must also validate the instance lexical (stE050: "1" and
96
+ // "true" both xs:boolean; stE055: "1.0"/"1.000" both xs:float).
97
+ // Raw strcmp wrongly rejected value-equal forms. Real W3C fixtures
98
+ // (msData/simpleType, vendored under libxml2-cases/stE-union-fixed).
99
+ TEST(XsdUnionFixed, StE050BooleanMemberAcceptsBoth) {
100
+ EXPECT_EQ(validate_case(cases_path("stE-union-fixed/stE050.xsd"),
101
+ cases_path("stE-union-fixed/stE050.xml")),
102
+ 1);
103
+ }
104
+
105
+ TEST(XsdUnionFixed, StE055FloatMemberAcceptsBothSpellings) {
106
+ EXPECT_EQ(validate_case(cases_path("stE-union-fixed/stE055.xsd"),
107
+ cases_path("stE-union-fixed/stE055.xml")),
108
+ 1);
109
+ }
110
+
111
+ TEST(XsdUnionFixed, NonMemberValueStillRejects) {
112
+ /* "2.0" validates through the union (float) but differs from the
113
+ * fixed 1.0 in the value space — the fixed constraint holds. */
114
+ LeptrisStatus st = LEPTRIS_OK;
115
+ LeptrisXsdSchema s = leptris_xsd_compile_file(
116
+ cases_path("stE-union-fixed/stE055.xsd").c_str(), &st);
117
+ ASSERT_NE(s, (LeptrisXsdSchema)0);
118
+ const char other[] = "<root>2.000</root>";
119
+ LeptrisDocument d = leptris_parse_string(other, strlen(other), &st);
120
+ ASSERT_NE(d, nullptr);
121
+ EXPECT_EQ(leptris_xsd_validate(s, d), 0)
122
+ << "fixed 1.0 accepted the value 2.0";
123
+ leptris_document_free(d);
124
+ leptris_xsd_free(s);
125
+ }
126
+
127
+ // ---- leptris-rs#46 (elemZ020): particle typing is ns-aware ------
128
+ // Real W3C fixture msData/element/elemZ020: a form="unqualified"
129
+ // local particle (xs:int) and a same-name substitution member
130
+ // (xs:boolean) discriminate by namespace. The namespaced child
131
+ // types through its member declaration; the no-ns child types
132
+ // through the unqualified particle.
133
+
134
+ TEST(XsdSubstNs, ElemZ020RealFixtureValidates) {
135
+ EXPECT_EQ(validate_case(cases_path("elemZ020-subst-ns/elemZ020.xsd"),
136
+ cases_path("elemZ020-subst-ns/elemZ020.xml")),
137
+ 1);
138
+ }
139
+
140
+ TEST(XsdSubstNs, NamespacedChildTypedByMemberNotUnqualifiedParticle) {
141
+ LeptrisStatus st = LEPTRIS_OK;
142
+ LeptrisXsdSchema s = leptris_xsd_compile_file(
143
+ cases_path("elemZ020-subst-ns/elemZ020.xsd").c_str(), &st);
144
+ ASSERT_NE(s, (LeptrisXsdSchema)0);
145
+ /* "true" is boolean (the member), not int (the unqualified
146
+ * particle) — the ns-strict member binding types it. */
147
+ const char q[] = "<?xml version=\"1.0\"?>\n"
148
+ "<foo:root xmlns:foo=\"foo\">"
149
+ "<foo:foo>true</foo:foo></foo:root>";
150
+ LeptrisDocument d = leptris_parse_string(q, strlen(q), &st);
151
+ ASSERT_NE(d, nullptr);
152
+ EXPECT_EQ(leptris_xsd_validate(s, d), 1);
153
+ leptris_document_free(d);
154
+ /* int lexical in the member's slot still rejects */
155
+ const char bad[] = "<?xml version=\"1.0\"?>\n"
156
+ "<foo:root xmlns:foo=\"foo\">"
157
+ "<foo:foo>123</foo:foo></foo:root>";
158
+ d = leptris_parse_string(bad, strlen(bad), &st);
159
+ ASSERT_NE(d, nullptr);
160
+ EXPECT_EQ(leptris_xsd_validate(s, d), 0);
161
+ leptris_document_free(d);
162
+ /* the no-ns child rides the form="unqualified" particle */
163
+ const char u[] = "<?xml version=\"1.0\"?>\n"
164
+ "<foo:root xmlns:foo=\"foo\">"
165
+ "<foo>123</foo></foo:root>";
166
+ d = leptris_parse_string(u, strlen(u), &st);
167
+ ASSERT_NE(d, nullptr);
168
+ EXPECT_EQ(leptris_xsd_validate(s, d), 1);
169
+ leptris_document_free(d);
170
+ /* boolean lexical in the unqualified particle's slot rejects */
171
+ const char bad2[] = "<?xml version=\"1.0\"?>\n"
172
+ "<foo:root xmlns:foo=\"foo\">"
173
+ "<foo>true</foo></foo:root>";
174
+ d = leptris_parse_string(bad2, strlen(bad2), &st);
175
+ ASSERT_NE(d, nullptr);
176
+ EXPECT_EQ(leptris_xsd_validate(s, d), 0);
177
+ leptris_document_free(d);
178
+ leptris_xsd_free(s);
179
+ }
@@ -1230,6 +1230,32 @@ int validate_doc(const char* schema, const char* xml) {
1230
1230
  return r;
1231
1231
  }
1232
1232
 
1233
+ // leptris#1964: the anyAttribute grammar rides attributeGroup
1234
+ // REFS too — attgD019's ##any wildcard lives inside the referenced
1235
+ // group, not the referencing complexType's direct children, so the
1236
+ // type's grammar captured empty and strict admission rejected
1237
+ // attributes the wildcard admits. compile-set variant: the head
1238
+ // (no tns) + the foo-tns member; W3C attgD019 expects VALID.
1239
+ TEST(XsdCompile, StrictAnyAttrGrammarRidesAttributeGroupRefs) {
1240
+ LeptrisStatus st = LEPTRIS_OK;
1241
+ const char* paths[] = {
1242
+ LEPTRIS_XSD_CASES_DIR "/attgD019-set/attgD019.xsd",
1243
+ LEPTRIS_XSD_CASES_DIR "/attgD019-set/attgD019a.xsd",
1244
+ };
1245
+ LeptrisXsdSchema s = leptris_xsd_compile_set(paths, 2, &st);
1246
+ ASSERT_NE(s, (LeptrisXsdSchema)0) << "status " << (int)st;
1247
+ const char inst[] =
1248
+ "<doc xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
1249
+ " xmlns:x=\"foo\">"
1250
+ "<elem att1=\"123\" x:foo=\"foo\"/></doc>";
1251
+ LeptrisDocument d = leptris_parse_string(inst, strlen(inst), &st);
1252
+ ASSERT_NE(d, nullptr);
1253
+ EXPECT_EQ(leptris_xsd_validate(s, d), 1)
1254
+ << leptris_xsd_error_at(s, 0);
1255
+ leptris_document_free(d);
1256
+ leptris_xsd_free(s);
1257
+ }
1258
+
1233
1259
  TEST(XsdValidate, ValidDocumentPasses) {
1234
1260
  EXPECT_EQ(validate_doc(k_v_schema,
1235
1261
  "<rows version=\"2\" status=\"ok\">"
@@ -1435,6 +1461,53 @@ TEST(XsdDatatypes, TemporalEnumerationComparesByValue) {
1435
1461
  leptris_xsd_free(s);
1436
1462
  }
1437
1463
 
1464
+ // W3C XSD suite msData/element/elemZ020: particle typing is
1465
+ // NAMESPACE-aware. A form="unqualified" local particle types only
1466
+ // no-namespace children; a namespaced child of the same local name
1467
+ // types through its own (substitution-member) declaration. The
1468
+ // first-name-match DFS bound BOTH to whichever same-name particle
1469
+ // it saw first (elemZ020: 'true' failed xsd:int, '123' failed
1470
+ // xsd:boolean).
1471
+ TEST(XsdValidate, ParticleTypingIsNamespaceAware) {
1472
+ const char* sch =
1473
+ "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
1474
+ " elementFormDefault=\"qualified\" targetNamespace=\"foo\""
1475
+ " xmlns=\"foo\">"
1476
+ "<xsd:element name=\"e1\" type=\"xsd:boolean\"/>"
1477
+ "<xsd:element name=\"foo\" substitutionGroup=\"e1\""
1478
+ " type=\"xsd:boolean\"/>"
1479
+ "<xsd:element name=\"root\" type=\"B\"/>"
1480
+ "<xsd:complexType name=\"B\">"
1481
+ "<xsd:choice maxOccurs=\"1000\">"
1482
+ "<xsd:element ref=\"e1\"/>"
1483
+ "<xsd:element name=\"foo\" type=\"xsd:int\""
1484
+ " form=\"unqualified\"/>"
1485
+ "</xsd:choice></xsd:complexType></xsd:schema>";
1486
+ /* namespaced member: typed by its own boolean declaration */
1487
+ EXPECT_EQ(validate_doc(sch,
1488
+ "<?xml version=\"1.0\"?>\n"
1489
+ "<foo:root xmlns:foo=\"foo\"><foo:foo>true</foo:foo>"
1490
+ "</foo:root>"), 1);
1491
+ /* no-namespace child: typed by the unqualified local particle */
1492
+ EXPECT_EQ(validate_doc(sch,
1493
+ "<?xml version=\"1.0\"?>\n"
1494
+ "<foo:root xmlns:foo=\"foo\"><foo>123</foo></foo:root>"), 1);
1495
+ /* the full suite doc: both shapes interleaved [valid] */
1496
+ EXPECT_EQ(validate_doc(sch,
1497
+ "<?xml version=\"1.0\"?>\n"
1498
+ "<foo:root xmlns:foo=\"foo\"><foo:foo>true</foo:foo>"
1499
+ "<foo>123</foo><foo:foo>true</foo:foo><foo>123</foo>"
1500
+ "</foo:root>"), 1);
1501
+ /* wrong content for each binding still rejects */
1502
+ EXPECT_EQ(validate_doc(sch,
1503
+ "<?xml version=\"1.0\"?>\n"
1504
+ "<foo:root xmlns:foo=\"foo\"><foo:foo>123</foo:foo>"
1505
+ "</foo:root>"), 0);
1506
+ EXPECT_EQ(validate_doc(sch,
1507
+ "<?xml version=\"1.0\"?>\n"
1508
+ "<foo:root xmlns:foo=\"foo\"><foo>true</foo></foo:root>"), 0);
1509
+ }
1510
+
1438
1511
  TEST(XsdValidate, ContentModelViolationReports) {
1439
1512
  EXPECT_EQ(validate_doc(k_v_schema,
1440
1513
  "<rows version=\"1\">"
@@ -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.407",
4
+ "version": "1.9.409",
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.407.0
4
+ version: 1.9.409.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -1281,6 +1281,8 @@ files:
1281
1281
  - vendor-src/libleptris/test/xsd/libxml2-cases/anyAttr.importB.1_0.xsd
1282
1282
  - vendor-src/libleptris/test/xsd/libxml2-cases/anyAttr1_0.xml
1283
1283
  - vendor-src/libleptris/test/xsd/libxml2-cases/anyAttr1_0.xsd
1284
+ - vendor-src/libleptris/test/xsd/libxml2-cases/attgD019-set/attgD019.xsd
1285
+ - vendor-src/libleptris/test/xsd/libxml2-cases/attgD019-set/attgD019a.xsd
1284
1286
  - vendor-src/libleptris/test/xsd/libxml2-cases/attr0_0.xml
1285
1287
  - vendor-src/libleptris/test/xsd/libxml2-cases/attr0_0.xsd
1286
1288
  - vendor-src/libleptris/test/xsd/libxml2-cases/attruse_0_0.xml
@@ -1375,6 +1377,8 @@ files:
1375
1377
  - vendor-src/libleptris/test/xsd/libxml2-cases/dur_0.xsd
1376
1378
  - vendor-src/libleptris/test/xsd/libxml2-cases/elem0_0.xml
1377
1379
  - vendor-src/libleptris/test/xsd/libxml2-cases/elem0_0.xsd
1380
+ - vendor-src/libleptris/test/xsd/libxml2-cases/elemZ020-subst-ns/elemZ020.xml
1381
+ - vendor-src/libleptris/test/xsd/libxml2-cases/elemZ020-subst-ns/elemZ020.xsd
1378
1382
  - vendor-src/libleptris/test/xsd/libxml2-cases/element-err_0.xml
1379
1383
  - vendor-src/libleptris/test/xsd/libxml2-cases/element-err_0.xsd
1380
1384
  - vendor-src/libleptris/test/xsd/libxml2-cases/element-minmax-err_0.xml
@@ -1586,6 +1590,10 @@ files:
1586
1590
  - vendor-src/libleptris/test/xsd/libxml2-cases/src-element2-2_0.xsd
1587
1591
  - vendor-src/libleptris/test/xsd/libxml2-cases/src-element3_0.xml
1588
1592
  - vendor-src/libleptris/test/xsd/libxml2-cases/src-element3_0.xsd
1593
+ - vendor-src/libleptris/test/xsd/libxml2-cases/stE-union-fixed/stE050.xml
1594
+ - vendor-src/libleptris/test/xsd/libxml2-cases/stE-union-fixed/stE050.xsd
1595
+ - vendor-src/libleptris/test/xsd/libxml2-cases/stE-union-fixed/stE055.xml
1596
+ - vendor-src/libleptris/test/xsd/libxml2-cases/stE-union-fixed/stE055.xsd
1589
1597
  - vendor-src/libleptris/test/xsd/libxml2-cases/subst-group-1_0.xsd
1590
1598
  - vendor-src/libleptris/test/xsd/libxml2-cases/subst-group-1_1.xml
1591
1599
  - vendor-src/libleptris/test/xsd/libxml2-cases/union2_1.xml