leptris 1.9.429.0 → 1.9.430.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be08e6e08742584fcc0523bf76478c5a5978b9bd53a6169d13e6f4e7eab5a4c1
4
- data.tar.gz: 4f4b0061724dccd35e8b2bccb74578183a380ffec6d6cda8188cd65c5e43883b
3
+ metadata.gz: d385f809d3e15740fdd559f06d65e4984f6823ccd4fc89279fb41b02ac95b711
4
+ data.tar.gz: 1ff2254a1804455ed540c4cdd748672117e3d908ff68c60adc23f1fe84091edf
5
5
  SHA512:
6
- metadata.gz: e43dae55cc12500816a1f3481e5d3067e5c9647641e1c7be741de4af2f6697066238e6701cca34810a52d80220183a8221d7fe680a4e9730980dd061b0e7da79
7
- data.tar.gz: 34cbe840aeb0877fbab52973712b9eaa993198ead5fd5b6825c3356312d9fb8f463baabae7b5d70e93196250ac67a61b4572edc8fb6951219a3072ac50e78210
6
+ metadata.gz: 382c0432a947f1a9722288ad9d7d277e1cf508a3efbb270c6438a78cec141e90d1f4d7ffca82464bf4ee4f6bf0cd0da76651ae731744118f59becc6ae21ae447
7
+ data.tar.gz: b6321c649b358dc94f43c98ca7a901831064cd0322b5a62460fd028ae03002e29e8d2da18db72ada2e2daf767c9517d9623604206a4a1b391ab677c486ba1ec7
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ### Fixed
4
4
 
5
+ - RelaxNG: a `combine="interleave"` define can add an element between
6
+ the members of a base sequence again (regression in 1.9.428.0, fixed
7
+ by engine 1.9.429; leptris/leptris#2094). Regression spec with the
8
+ include-override schema pair from #650.
5
9
  - Rebuild the native object under the Ruby that performs final packaging.
6
10
  Restoring the job Ruby after the per-minor release loop could reuse the
7
11
  last minor's object and overwrite the job minor's bundle with a different
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.429"
11
+ LIBLEPTRIS_VERSION = "1.9.430"
12
12
 
13
13
  # THE SSOT for the per-minor native bundle list (ruby#645): one line,
14
14
  # space-separated, consumed by the Rakefile, the per-minor builder's
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leptris
4
- VERSION = "1.9.429.0"
4
+ VERSION = "1.9.430.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.429
4
+ - libleptris v1.9.430
5
5
  - utf8proc v2.11.0
6
6
 
7
7
  Rebuild by hand:
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.9.430] - 2026-11-20
4
+
5
+ ### Fixed
6
+
7
+ - **RELAX NG: the OpenMath corpus now validates verdict-identical to Jing — 345/345 documents, zero mismatches.** The attr-choice collection walk treated the cyclic content graph (`omel → OME/notom → omel`) as a tree and collected the same attribute-choice once per lap up to the selection cap while the branch search's depth cap is lower, so every element whose content could reach the cycle rejected with "attribute combination matches no branch of the attribute choice" after seconds of re-walking — the corpus-wide failure since 1.9.427 (#2079), independent of the interleave work. alg1-001: 30s-wrong-verdict → sub-millisecond-valid. The walk now carries a pointer set and visits each node once. leptris#2103, disposition on #2088.
8
+ - **RELAX NG regression (1.9.428–429)**: zero-width group members hold and advance the interleave cursor instead of finishing the group, so the simplest OMATTR attribution document — valid on 1.9.428, rejected on 1.9.429 — validates again; misplaced merged elements find their own element pattern. leptris#2099.
9
+ - RELAX NG: the interleave cursor machine memoizes its search states. An interleave of repeats followed by a sibling — `interleave(a*, b*), c` over `(a b)×N c` — spent the whole 200 000-step budget already at N = 10; it now takes a few hundred steps, polynomial in the child count. The failure diagnosis keeps the remainder of the interleave branch that consumed a child, so a document with an unrelated error no longer also reports `element "flavor" not allowed here` for a correctly placed merged element. By @andrew2net. leptris#2098.
10
+ - Build: drop the stale amalgamation rename of xslt_register_ufn_handlers. leptris#2100.
11
+
3
12
  ## [1.9.429] - 2026-11-19
4
13
 
5
14
  ### Fixed
@@ -3,7 +3,7 @@
3
3
  cmake_minimum_required(VERSION 3.20)
4
4
 
5
5
  project(leptris
6
- VERSION 1.9.429
6
+ VERSION 1.9.430
7
7
  DESCRIPTION "Fast XML parser and XPath evaluator in pure C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -176,8 +176,6 @@ if(LEPTRIS_AMALGAMATED)
176
176
  "leptris/common/format_number.c:parse_pattern=fmt_num_parse_pattern"
177
177
  "leptris/sax/iterparse.c:set_error=iterparse_set_error"
178
178
  "leptris/xpath/vm.c:xpath_context_document=vm_xpath_context_document"
179
- "leptris/xpath/xpath_public.c:xslt_register_ufn_handlers=xslt_register_ufn_handlers_impl"
180
- "leptris/xslt/xslt_functions.c:xslt_register_ufn_handlers=xslt_register_ufn_handlers_impl"
181
179
  "leptris/xslt/xslt_exec.c:utf8_encode=xslt_utf8_encode"
182
180
  "leptris/xslt/xslt_exec.c:ws_only=xslt_ws_only"
183
181
  "leptris/rng/validate.c:match_seq=rng_match_seq"
@@ -347,10 +347,6 @@ typedef struct {
347
347
 
348
348
  static int check_required_list_sel(RngVal* v, RngPattern* head,
349
349
  LeptrisElement e, const AttrSel* sel);
350
- static int check_required_list(RngVal* v, RngPattern* head,
351
- LeptrisElement e) {
352
- return check_required_list_sel(v, head, e, NULL);
353
- }
354
350
 
355
351
  static RngPattern* attr_sel_branch(const AttrSel* sel,
356
352
  const RngPattern* choice) {
@@ -496,11 +492,49 @@ static int check_required_node_sel(RngVal* v, RngPattern* c,
496
492
  return 1;
497
493
  }
498
494
 
495
+ /* The content graph is CYCLIC (openmath2.rng: omel -> OME/notom ->
496
+ * omel): a naive tree walk revisits the same nodes once per lap and
497
+ * collected the same attr-choice up to RNG_ATTR_SEL_MAX times, while
498
+ * the selection search's depth cap is lower — every element whose
499
+ * content could reach the cycle rejected, and the re-walk cost
500
+ * seconds per element. The walk carries a pointer set and visits
501
+ * each node once. */
502
+ #define RNG_COLLECT_SEEN_MAX 512
503
+
504
+ typedef struct {
505
+ const RngPattern* slot[RNG_COLLECT_SEEN_MAX];
506
+ } CollectSeen;
507
+
508
+ static int collect_seen_add(CollectSeen* s, const RngPattern* p) {
509
+ size_t h = ((uintptr_t)p >> 4) % RNG_COLLECT_SEEN_MAX;
510
+ for (size_t i = 0; i < RNG_COLLECT_SEEN_MAX; i++) {
511
+ size_t j = (h + i) % RNG_COLLECT_SEEN_MAX;
512
+ if (s->slot[j] == p) return 0;
513
+ if (!s->slot[j]) {
514
+ s->slot[j] = p;
515
+ return 1;
516
+ }
517
+ }
518
+ return 1;
519
+ }
520
+
521
+ static void collect_walk(RngVal* v, RngPattern* p, int depth, AttrSel* out,
522
+ CollectSeen* seen);
523
+
499
524
  /* Collect the attr-consuming CHOICE nodes through the content
500
- * (refs expanded, depth-capped). */
525
+ * (refs expanded, depth-capped, cycle-safe). */
501
526
  static void collect_attr_choices(RngVal* v, RngPattern* p, int depth,
502
527
  AttrSel* out) {
503
528
  if (!p || depth > 24) return;
529
+ CollectSeen seen;
530
+ memset(&seen, 0, sizeof(seen));
531
+ collect_walk(v, p, depth, out, &seen);
532
+ }
533
+
534
+ static void collect_walk(RngVal* v, RngPattern* p, int depth, AttrSel* out,
535
+ CollectSeen* seen) {
536
+ if (!p || depth > 24) return;
537
+ if (!collect_seen_add(seen, p)) return;
504
538
  for (RngPattern* c = p->first_child; c; c = c->next) {
505
539
  if (c->kind == RNG_CHOICE) {
506
540
  int consumes = 0;
@@ -515,10 +549,10 @@ static void collect_attr_choices(RngVal* v, RngPattern* p, int depth,
515
549
  }
516
550
  if (c->kind == RNG_REF) {
517
551
  RngDefine* d = find_define(v->g, c->name);
518
- if (d && d->body) collect_attr_choices(v, d->body, depth + 1, out);
552
+ if (d && d->body) collect_walk(v, d->body, depth + 1, out, seen);
519
553
  continue;
520
554
  }
521
- collect_attr_choices(v, c, depth + 1, out);
555
+ collect_walk(v, c, depth + 1, out, seen);
522
556
  }
523
557
  }
524
558
 
@@ -610,6 +644,20 @@ static size_t match_seq(RngVal* v, RngPattern* p, LeptrisNodeRef* kids,
610
644
  * chain; the search advances one branch's head pattern at the shared
611
645
  * frontier, recurses, and backtracks on overall failure. Jing does
612
646
  * the same search over its interleave automaton. */
647
+ /* leptris#2093: one memo slot per visited search state. The result of
648
+ * rng_interleave_try depends only on (frontier, every cursor, every
649
+ * done flag, held mask), and full enumeration reaches the same state
650
+ * along many paths — interleave(a*, b*) followed by a sibling never
651
+ * hits the best == n early exit, so (a b)x40 exhausted the budget and
652
+ * rejected a valid document. Memoized, the search is polynomial. */
653
+ typedef struct {
654
+ size_t hash; /* 0 = empty slot */
655
+ size_t i;
656
+ unsigned mask;
657
+ size_t off; /* this state's cur[]/done[] in the pool */
658
+ size_t val; /* the memoized result */
659
+ } IlvMemo;
660
+
613
661
  typedef struct {
614
662
  RngPattern* cur[64]; /* the branch's remaining member pattern */
615
663
  int unit[64]; /* the branch is a single non-group pattern */
@@ -620,8 +668,90 @@ typedef struct {
620
668
  past the budget the match fails
621
669
  conservatively (the diagnose pass then
622
670
  reports the shortfall) */
671
+ IlvMemo* memo; /* open addressing, power-of-two capacity */
672
+ size_t memo_cap, memo_len;
673
+ RngPattern** pool; /* cn cursors + cn done markers per state */
674
+ size_t pool_len, pool_cap;
623
675
  } IlvState;
624
676
 
677
+ /* done[b] is stored in the pool as a non-NULL marker. */
678
+ static RngPattern ilv_done_mark;
679
+
680
+ static size_t ilv_hash(const IlvState* st, size_t i, unsigned mask) {
681
+ size_t h = (size_t)1469598103u ^ i;
682
+ h = h * 1099511u ^ mask;
683
+ for (size_t b = 0; b < st->cn; b++) {
684
+ h = h * 1099511u ^ (size_t)(st->cur[b]);
685
+ h = h * 1099511u ^ (size_t)st->done[b];
686
+ }
687
+ return h ? h : 1;
688
+ }
689
+
690
+ static int ilv_same(const IlvState* st, const IlvMemo* m, size_t i,
691
+ unsigned mask) {
692
+ if (m->i != i || m->mask != mask) return 0;
693
+ RngPattern* const* rec = st->pool + m->off;
694
+ for (size_t b = 0; b < st->cn; b++) {
695
+ if (rec[b] != st->cur[b]) return 0;
696
+ if ((rec[st->cn + b] != NULL) != (st->done[b] != 0)) return 0;
697
+ }
698
+ return 1;
699
+ }
700
+
701
+ static const IlvMemo* ilv_lookup(const IlvState* st, size_t h, size_t i,
702
+ unsigned mask) {
703
+ if (!st->memo) return NULL;
704
+ for (size_t k = h & (st->memo_cap - 1);; k = (k + 1) & (st->memo_cap - 1)) {
705
+ const IlvMemo* m = &st->memo[k];
706
+ if (!m->hash) return NULL;
707
+ if (m->hash == h && ilv_same(st, m, i, mask)) return m;
708
+ }
709
+ }
710
+
711
+ /* Best effort: on an allocation failure the state is simply not
712
+ * memoized (the step budget still bounds the search). */
713
+ static void ilv_store(IlvState* st, size_t h, size_t i, unsigned mask,
714
+ size_t val) {
715
+ if (st->memo_len * 2 >= st->memo_cap) {
716
+ size_t cap = st->memo_cap ? st->memo_cap * 2 : 256;
717
+ if (cap > ((size_t)1 << 22)) return;
718
+ IlvMemo* t = (IlvMemo*)calloc(cap, sizeof(*t));
719
+ if (!t) return;
720
+ for (size_t k = 0; k < st->memo_cap; k++) {
721
+ if (!st->memo[k].hash) continue;
722
+ size_t j = st->memo[k].hash & (cap - 1);
723
+ while (t[j].hash) j = (j + 1) & (cap - 1);
724
+ t[j] = st->memo[k];
725
+ }
726
+ free(st->memo);
727
+ st->memo = t;
728
+ st->memo_cap = cap;
729
+ }
730
+ if (st->pool_len + 2 * st->cn > st->pool_cap) {
731
+ size_t cap = st->pool_cap ? st->pool_cap * 2 : 1024;
732
+ while (cap < st->pool_len + 2 * st->cn) cap *= 2;
733
+ RngPattern** p =
734
+ (RngPattern**)realloc(st->pool, cap * sizeof(*p));
735
+ if (!p) return;
736
+ st->pool = p;
737
+ st->pool_cap = cap;
738
+ }
739
+ size_t off = st->pool_len;
740
+ for (size_t b = 0; b < st->cn; b++) {
741
+ st->pool[off + b] = st->cur[b];
742
+ st->pool[off + st->cn + b] = st->done[b] ? &ilv_done_mark : NULL;
743
+ }
744
+ st->pool_len += 2 * st->cn;
745
+ size_t k = h & (st->memo_cap - 1);
746
+ while (st->memo[k].hash) k = (k + 1) & (st->memo_cap - 1);
747
+ st->memo[k].hash = h;
748
+ st->memo[k].i = i;
749
+ st->memo[k].mask = mask;
750
+ st->memo[k].off = off;
751
+ st->memo[k].val = val;
752
+ st->memo_len++;
753
+ }
754
+
625
755
  static size_t rng_interleave_try(RngVal* v, IlvState* st,
626
756
  LeptrisNodeRef* kids, size_t n,
627
757
  size_t i, unsigned held_mask);
@@ -652,6 +782,9 @@ static size_t rng_interleave_try(RngVal* v, IlvState* st,
652
782
  if (!st->done[b]) break;
653
783
  }
654
784
  if (b == st->cn) return i; /* every branch exhausted */
785
+ size_t h = ilv_hash(st, i, held_mask);
786
+ const IlvMemo* seen = ilv_lookup(st, h, i, held_mask);
787
+ if (seen) return seen->val;
655
788
  if (++st->steps > 200000) return (size_t)-1;
656
789
  /* The search returns the FURTHEST completion, not the first: a
657
790
  * branch finishing early can complete at a position that strands
@@ -693,11 +826,24 @@ static size_t rng_interleave_try(RngVal* v, IlvState* st,
693
826
  best = out;
694
827
  if (best == n) break;
695
828
  }
696
- /* or the branch finishes here */
829
+ /* or the member is skipped. A unit branch (or a group's
830
+ * last member) finishes here; a group branch moves its
831
+ * cursor to the NEXT member - a zero-width optional,
832
+ * attribute or empty repeat in the middle of a group must
833
+ * not finish the whole group (doctype, subdoctype?,
834
+ * flavor: skipping subdoctype still requires flavor, and
835
+ * still admits it). The cursor strictly advances, so the
836
+ * same-frontier recursion terminates. */
697
837
  RngPattern* save = st->cur[b];
698
838
  int save_done = st->done[b];
699
- st->done[b] = 1;
700
- size_t out = rng_interleave_try(v, st, kids, n, r, -1);
839
+ size_t out;
840
+ if (st->unit[b] || h->next == NULL) {
841
+ st->done[b] = 1;
842
+ out = rng_interleave_try(v, st, kids, n, r, -1);
843
+ } else {
844
+ st->cur[b] = h->next;
845
+ out = rng_interleave_try(v, st, kids, n, r, held_mask);
846
+ }
701
847
  st->cur[b] = save; /* backtrack */
702
848
  st->done[b] = save_done;
703
849
  if (out != (size_t)-1 && (best == (size_t)-1 || out > best))
@@ -712,6 +858,7 @@ static size_t rng_interleave_try(RngVal* v, IlvState* st,
712
858
  v->err[0] = 0;
713
859
  }
714
860
  }
861
+ ilv_store(st, h, i, held_mask, best);
715
862
  return best;
716
863
  }
717
864
 
@@ -798,7 +945,8 @@ static size_t match_seq(RngVal* v, RngPattern* p, LeptrisNodeRef* kids,
798
945
  st.done[st.cn] = 0;
799
946
  st.cn++;
800
947
  }
801
- size_t out = rng_interleave_try(v, &st, kids, n, idx, 0);
948
+ size_t out = rng_interleave_try(v, &st, kids, n, idx, 0); free(st.memo);
949
+ free(st.pool);
802
950
  if (out == (size_t)-1) {
803
951
  v->failed = 0;
804
952
  v->err[0] = 0;
@@ -1494,15 +1642,21 @@ static DiagCell* d_state(RngVal* v, DiagCell* s, const char* x, int* ok) {
1494
1642
  for (RngPattern* a = d->first_child; a; a = a->next) {
1495
1643
  DiagCell tmp; tmp.item = a; tmp.next = NULL;
1496
1644
  int sub = 0;
1497
- d_state(v, &tmp, x, &sub);
1645
+ DiagCell* rest = d_state(v, &tmp, x, &sub);
1498
1646
  if (!sub) continue;
1499
1647
  consumed = 1;
1500
- /* Survivors = other children (this one consumed
1501
- * once; single-use children drop, repeats keep). */
1648
+ /* Survivors = the other children plus the
1649
+ * consuming child's RESIDUAL in its place: a
1650
+ * group branch keeps its tail (leptris#2093), a
1651
+ * repeat stays active; a used-up single drops. */
1502
1652
  RngPattern* kids = NULL;
1503
1653
  for (RngPattern* o = d->first_child; o; o = o->next) {
1504
- if (o == a) continue;
1505
- RngPattern* cp = dpat_copy(v, o);
1654
+ RngPattern* src = o;
1655
+ if (o == a) {
1656
+ if (!rest) continue;
1657
+ src = rest->item;
1658
+ }
1659
+ RngPattern* cp = dpat_copy(v, src);
1506
1660
  if (!cp) { consumed = 0; break; }
1507
1661
  cp->next = kids; kids = cp;
1508
1662
  }
@@ -1611,6 +1765,69 @@ static RngPattern* find_element_pattern(RngVal* v, RngPattern* p,
1611
1765
  return NULL;
1612
1766
  }
1613
1767
 
1768
+ static int collect_attr_patterns(RngVal* v, RngPattern* head,
1769
+ RngPattern** out, int* optional,
1770
+ int n, int cap, int opt,
1771
+ RngPattern** seen, int* nseen);
1772
+
1773
+ /* Element patterns named `x` inside `p`, NOT following refs (every
1774
+ * define is visited by the caller, so refs add nothing but cycles).
1775
+ * Collects up to `cap` hits into `out`. */
1776
+ static int collect_named_elements(RngPattern* p, const char* x,
1777
+ RngPattern** out, int n, int cap,
1778
+ int depth) {
1779
+ for (; p && n < cap; p = p->next) {
1780
+ if (depth > 64) return n;
1781
+ if (p->kind == RNG_REF) continue;
1782
+ if (p->kind == RNG_ELEMENT && !p->any_name && p->name &&
1783
+ strcmp(p->name, x) == 0)
1784
+ out[n++] = p;
1785
+ n = collect_named_elements(p->first_child, x, out, n, cap,
1786
+ depth + 1);
1787
+ }
1788
+ return n;
1789
+ }
1790
+
1791
+ /* Does every attribute on `e` have a same-named attribute pattern in
1792
+ * element pattern `el`? */
1793
+ static int attrs_named_in(RngVal* v, RngPattern* el, LeptrisElement e) {
1794
+ RngPattern* cands[64];
1795
+ int cand_opt[64];
1796
+ RngPattern* seen[128];
1797
+ int nseen = 0;
1798
+ int nc = collect_attr_patterns(v, el->first_child, cands, cand_opt,
1799
+ 0, 64, 0, seen, &nseen);
1800
+ for (struct leptris_attribute* a =
1801
+ leptris_element_get_first_attribute(e);
1802
+ a; a = leptris_attr_next(a)) {
1803
+ const char* name = attr_cname(a);
1804
+ int found = 0;
1805
+ for (int i = 0; i < nc && !found; i++)
1806
+ if (cands[i]->name && strcmp(cands[i]->name, name) == 0)
1807
+ found = 1;
1808
+ if (!found) return 0;
1809
+ }
1810
+ return 1;
1811
+ }
1812
+
1813
+ /* leptris#1704 recovery target for a misplaced element: the element
1814
+ * pattern(s) named `x` anywhere in the grammar, as Jing's recovery
1815
+ * does - grammars name the define after the role, not the element
1816
+ * (basicdoc: <define name="paragraph"><element name="p">). Prefer a
1817
+ * pattern that declares every attribute the instance carries, so the
1818
+ * value check runs against the definition that owns the attribute. */
1819
+ static RngPattern* recovery_element_pattern(RngVal* v, LeptrisElement e,
1820
+ const char* x) {
1821
+ RngPattern* hits[32];
1822
+ int n = collect_named_elements(v->g->start, x, hits, 0, 32, 0);
1823
+ for (RngDefine* d = v->g->defines; d && n < 32; d = d->next)
1824
+ n = collect_named_elements(d->body, x, hits, n, 32, 0);
1825
+ if (n == 0) return NULL;
1826
+ for (int i = 0; i < n; i++)
1827
+ if (attrs_named_in(v, hits[i], e)) return hits[i];
1828
+ return hits[0];
1829
+ }
1830
+
1614
1831
  /* Diagnose a matched child element's own content (quiet verdict,
1615
1832
  * then recurse on failure). */
1616
1833
  static void diagnose_child(RngVal* v, RngPattern* content,
@@ -2092,10 +2309,16 @@ static void diagnose_element(RngVal* v, RngPattern* p, LeptrisElement e) {
2092
2309
  * enums) go invisible exactly where documents are most
2093
2310
  * broken. Jing reports both, position first. */
2094
2311
  {
2095
- RngDefine* own = find_define(v->g, x);
2096
- if (own && own->body)
2097
- diagnose_attrs(v, dpat_new(v, RNG_ELEMENT, own->body),
2098
- kid);
2312
+ RngPattern* own_el = recovery_element_pattern(v, kid, x);
2313
+ if (own_el) {
2314
+ diagnose_attrs(v, own_el, kid);
2315
+ } else {
2316
+ RngDefine* own = find_define(v->g, x);
2317
+ if (own && own->body)
2318
+ diagnose_attrs(v,
2319
+ dpat_new(v, RNG_ELEMENT, own->body),
2320
+ kid);
2321
+ }
2099
2322
  }
2100
2323
  /* Skip the offending child; position unchanged. */
2101
2324
  }
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="">
3
+ <start><element name="ext"><ref name="Ext"/></element></start>
4
+ <define name="Ext">
5
+ <element name="doctype"><empty/></element>
6
+ <element name="flavor"><empty/></element>
7
+ <zeroOrMore><element name="ics"><empty/></element></zeroOrMore>
8
+ </define>
9
+ </grammar>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="">
3
+ <include href="i2093-base.rng"/>
4
+ <define name="Ext" combine="interleave">
5
+ <optional><element name="price-code"><empty/></element></optional>
6
+ </define>
7
+ </grammar>
@@ -9,6 +9,7 @@
9
9
  #include "rng_internal.h"
10
10
 
11
11
  #include <cstring>
12
+ #include <string>
12
13
 
13
14
  namespace {
14
15
 
@@ -1800,6 +1801,226 @@ TEST(Rng2079AttrChoice, ExactlyOneBranchWins) {
1800
1801
  leptris_rng_free(rng);
1801
1802
  }
1802
1803
 
1804
+ /* ---- leptris#2110: a content choice of elements imposes no attr
1805
+ * requirement on the parent ------------------------------------------
1806
+ * Since #2079's whole-branch selection, the requirement walk's
1807
+ * unassigned-choice path descended through the alternatives into the
1808
+ * ELEMENT bodies and demanded the child elements' required attributes
1809
+ * from the PARENT (openmath2.rng's omel: OMS requires cd+name, checked
1810
+ * against OMOBJ) — every OpenMath document rejected in ~seconds.
1811
+ * An element alternative's requirements belong to the child element,
1812
+ * which is validated on its own visit. */
1813
+
1814
+ TEST(Rng2110AttrChoiceElementReq, ContentChoiceSparesParent) {
1815
+ const char* schema =
1816
+ "<grammar xmlns=\"http://relaxng.org/ns/structure/1.0\">"
1817
+ "<start><ref name=\"root\"/></start>"
1818
+ "<define name=\"root\">"
1819
+ "<element name=\"root\">"
1820
+ "<ref name=\"common\"/>"
1821
+ "<ref name=\"omel\"/>"
1822
+ "</element></define>"
1823
+ "<define name=\"common\">"
1824
+ "<optional><attribute name=\"id\"><data type=\"string\"/></attribute></optional>"
1825
+ "</define>"
1826
+ "<define name=\"omel\">"
1827
+ "<choice><ref name=\"a\"/><ref name=\"b\"/></choice>"
1828
+ "</define>"
1829
+ "<define name=\"a\">"
1830
+ "<element name=\"a\">"
1831
+ "<attribute name=\"req1\"><data type=\"string\"/></attribute>"
1832
+ "</element></define>"
1833
+ "<define name=\"b\">"
1834
+ "<element name=\"b\">"
1835
+ "<attribute name=\"req2\"><data type=\"string\"/></attribute>"
1836
+ "</element></define>"
1837
+ "</grammar>";
1838
+ LeptrisRelaxNG rng =
1839
+ leptris_rng_parse(schema, strlen(schema), nullptr);
1840
+ ASSERT_NE(rng, nullptr);
1841
+ LeptrisStatus st = LEPTRIS_OK;
1842
+ struct { const char* doc; int want; const char* why; } cases[] = {
1843
+ {"<root><a req1=\"x\"/></root>", 1,
1844
+ "element branch: the child's required attr is checked at the child"},
1845
+ {"<root><b req2=\"y\"/></root>", 1, "the other element branch"},
1846
+ {"<root id=\"i\"><a req1=\"x\"/></root>", 1,
1847
+ "the optional parent attr rides along"},
1848
+ {"<root/>", 0, "the choice itself is required"},
1849
+ {"<root><a req1=\"x\" req2=\"y\"/></root>", 0,
1850
+ "an attribute the chosen element does not allow still rejects"},
1851
+ };
1852
+ for (auto& c : cases) {
1853
+ LeptrisDocument d = leptris_parse_string(c.doc, strlen(c.doc), &st);
1854
+ ASSERT_NE(d, nullptr) << c.doc;
1855
+ EXPECT_EQ(leptris_rng_validate(rng, d), c.want)
1856
+ << c.why << " — doc: " << c.doc;
1857
+ leptris_document_free(d);
1858
+ }
1859
+ leptris_rng_free(rng);
1860
+ }
1861
+
1862
+ TEST(Rng2110AttrChoiceElementReq, OpenmathObjShape) {
1863
+ /* alg1-001 distillation: optional-folded attribute choices beside
1864
+ * a content choice of element refs (the openmath2.rng OMOBJ/omel
1865
+ * shape). Jing-verified valid; 1.9.427+ rejected it in seconds. */
1866
+ const char* schema =
1867
+ "<grammar xmlns=\"http://relaxng.org/ns/structure/1.0\">"
1868
+ "<start><element name=\"OMOBJ\">"
1869
+ "<optional><attribute name=\"version\"><data type=\"string\"/></attribute></optional>"
1870
+ "<ref name=\"common\"/>"
1871
+ "<ref name=\"omel\"/>"
1872
+ "</element></start>"
1873
+ "<define name=\"common\">"
1874
+ "<optional><attribute name=\"cdbase\"><data type=\"string\"/></attribute></optional>"
1875
+ "</define>"
1876
+ "<define name=\"omel\">"
1877
+ "<choice><ref name=\"OMS\"/><ref name=\"OMV\"/></choice>"
1878
+ "</define>"
1879
+ "<define name=\"OMS\"><element name=\"OMS\">"
1880
+ "<attribute name=\"cd\"><data type=\"string\"/></attribute>"
1881
+ "<attribute name=\"name\"><data type=\"string\"/></attribute>"
1882
+ "</element></define>"
1883
+ "<define name=\"OMV\"><element name=\"OMV\">"
1884
+ "<attribute name=\"name\"><data type=\"string\"/></attribute>"
1885
+ "</element></define>"
1886
+ "</grammar>";
1887
+ LeptrisRelaxNG rng =
1888
+ leptris_rng_parse(schema, strlen(schema), nullptr);
1889
+ ASSERT_NE(rng, nullptr);
1890
+ LeptrisStatus st = LEPTRIS_OK;
1891
+ struct { const char* doc; int want; const char* why; } cases[] = {
1892
+ {"<OMOBJ version=\"2.0\" cdbase=\"x\">"
1893
+ "<OMS cd=\"q\" name=\"forall\"/></OMOBJ>", 1,
1894
+ "the alg1-001 head shape"},
1895
+ {"<OMOBJ><OMS cd=\"q\" name=\"forall\"/></OMOBJ>", 1,
1896
+ "all optionals absent"},
1897
+ {"<OMOBJ><OMV name=\"a\"/></OMOBJ>", 1, "the other omel branch"},
1898
+ {"<OMOBJ><OMS cd=\"q\"/></OMOBJ>", 0,
1899
+ "the CHILD's own missing required attr still rejects"},
1900
+ {"<OMOBJ><OMX/></OMOBJ>", 0, "unknown child rejects"},
1901
+ };
1902
+ for (auto& c : cases) {
1903
+ LeptrisDocument d = leptris_parse_string(c.doc, strlen(c.doc), &st);
1904
+ ASSERT_NE(d, nullptr) << c.doc;
1905
+ EXPECT_EQ(leptris_rng_validate(rng, d), c.want)
1906
+ << c.why << " — doc: " << c.doc;
1907
+ leptris_document_free(d);
1908
+ }
1909
+ leptris_rng_free(rng);
1910
+ }
1911
+
1912
+ TEST(Rng2110AttrChoiceElementReq, NestedAttrChoiceStaysInTheChild) {
1913
+ /* The alg1-001 trigger: collect_attr_choices descended through
1914
+ * element boundaries, so the omel -> OMF ref pulled OMF's dec/hex
1915
+ * attribute-choice into OMOBJ's selection map — the search then
1916
+ * demanded OMF's attributes from OMOBJ and every assignment
1917
+ * failed ("attribute combination matches no branch"). An element
1918
+ * subtree's attr-choices belong to that element alone. */
1919
+ const char* schema =
1920
+ "<grammar ns=\"http://www.openmath.org/OpenMath\""
1921
+ " xmlns=\"http://relaxng.org/ns/structure/1.0\""
1922
+ " datatypeLibrary=\"http://www.w3.org/2001/XMLSchema-datatypes\">"
1923
+ "<start><element name=\"OMOBJ\">"
1924
+ "<optional><attribute name=\"version\"><data type=\"string\"/></attribute></optional>"
1925
+ "<ref name=\"common\"/>"
1926
+ "<ref name=\"omel\"/>"
1927
+ "</element></start>"
1928
+ "<define name=\"common\">"
1929
+ "<optional><attribute name=\"cdbase\"><data type=\"string\"/></attribute></optional>"
1930
+ "</define>"
1931
+ "<define name=\"omel\">"
1932
+ "<choice><ref name=\"OMS\"/><ref name=\"OMF\"/></choice>"
1933
+ "</define>"
1934
+ "<define name=\"OMS\"><element name=\"OMS\">"
1935
+ "<attribute name=\"cd\"><data type=\"string\"/></attribute>"
1936
+ "<attribute name=\"name\"><data type=\"string\"/></attribute>"
1937
+ "</element></define>"
1938
+ "<define name=\"OMF\"><element name=\"OMF\">"
1939
+ "<choice>"
1940
+ "<attribute name=\"dec\"><data type=\"double\"/></attribute>"
1941
+ "<attribute name=\"hex\"><data type=\"hexBinary\"/></attribute>"
1942
+ "</choice>"
1943
+ "</element></define>"
1944
+ "</grammar>";
1945
+ LeptrisRelaxNG rng =
1946
+ leptris_rng_parse(schema, strlen(schema), nullptr);
1947
+ ASSERT_NE(rng, nullptr);
1948
+ LeptrisStatus st = LEPTRIS_OK;
1949
+ struct { const char* doc; int want; const char* why; } cases[] = {
1950
+ {"<OMOBJ xmlns=\"http://www.openmath.org/OpenMath\" version=\"2.0\""
1951
+ " cdbase=\"x\"><OMS cd=\"q\" name=\"forall\"/></OMOBJ>", 1,
1952
+ "OMS branch: OMF's dec/hex choice must not be demanded here"},
1953
+ {"<OMOBJ xmlns=\"http://www.openmath.org/OpenMath\">"
1954
+ "<OMF dec=\"0.5\"/></OMOBJ>", 1,
1955
+ "the OMF branch: its own choice takes dec alone"},
1956
+ {"<OMOBJ xmlns=\"http://www.openmath.org/OpenMath\">"
1957
+ "<OMF hex=\"4142\"/></OMOBJ>", 1, "or hex alone"},
1958
+ {"<OMOBJ xmlns=\"http://www.openmath.org/OpenMath\">"
1959
+ "<OMF dec=\"0.5\" hex=\"41\"/></OMOBJ>", 0,
1960
+ "both branches at once still rejects"},
1961
+ };
1962
+ for (auto& c : cases) {
1963
+ LeptrisDocument d = leptris_parse_string(c.doc, strlen(c.doc), &st);
1964
+ ASSERT_NE(d, nullptr) << c.doc;
1965
+ EXPECT_EQ(leptris_rng_validate(rng, d), c.want)
1966
+ << c.why << " — doc: " << c.doc;
1967
+ leptris_document_free(d);
1968
+ }
1969
+ leptris_rng_free(rng);
1970
+ }
1971
+
1972
+ TEST(Rng2110AttrChoiceElementReq, CyclicContentDedupesTheAttrChoice) {
1973
+ /* openmath2.rng's real shape: omel reaches OME/notom, which reach
1974
+ * omel again. The collect walk treated the cyclic graph as a tree
1975
+ * (depth cap 24) and collected the same OMF choice once per lap —
1976
+ * 16 entries (RNG_ATTR_SEL_MAX) — while the selection search's
1977
+ * depth cap is 12, so no element could ever validate, and the
1978
+ * re-walk cost seconds per element. Collection must visit each
1979
+ * node once and keep one entry per distinct choice. */
1980
+ const char* schema =
1981
+ "<grammar xmlns=\"http://relaxng.org/ns/structure/1.0\">"
1982
+ "<start><element name=\"OMOBJ\">"
1983
+ "<optional><attribute name=\"version\"><data type=\"string\"/></attribute></optional>"
1984
+ "<ref name=\"omel\"/>"
1985
+ "</element></start>"
1986
+ "<define name=\"omel\">"
1987
+ "<choice><ref name=\"OMS\"/><ref name=\"OMF\"/><ref name=\"loop\"/></choice>"
1988
+ "</define>"
1989
+ "<define name=\"loop\"><element name=\"L\">"
1990
+ "<zeroOrMore><choice><ref name=\"omel\"/><ref name=\"loop\"/></choice></zeroOrMore>"
1991
+ "</element></define>"
1992
+ "<define name=\"OMS\"><element name=\"OMS\">"
1993
+ "<attribute name=\"cd\"><data type=\"string\"/></attribute>"
1994
+ "<attribute name=\"name\"><data type=\"string\"/></attribute>"
1995
+ "</element></define>"
1996
+ "<define name=\"OMF\"><element name=\"OMF\">"
1997
+ "<choice>"
1998
+ "<attribute name=\"dec\"><data type=\"double\"/></attribute>"
1999
+ "<attribute name=\"hex\"><data type=\"hexBinary\"/></attribute>"
2000
+ "</choice>"
2001
+ "</element></define>"
2002
+ "</grammar>";
2003
+ LeptrisRelaxNG rng =
2004
+ leptris_rng_parse(schema, strlen(schema), nullptr);
2005
+ ASSERT_NE(rng, nullptr);
2006
+ LeptrisStatus st = LEPTRIS_OK;
2007
+ struct { const char* doc; int want; const char* why; } cases[] = {
2008
+ {"<OMOBJ version=\"2.0\"><OMS cd=\"q\" name=\"forall\"/></OMOBJ>", 1,
2009
+ "the OMF choice must be collected once, not per cycle lap"},
2010
+ {"<OMOBJ><OMF dec=\"0.5\"/></OMOBJ>", 1, "dec alone"},
2011
+ {"<OMOBJ><L><OMS cd=\"q\" name=\"x\"/></L></OMOBJ>", 1,
2012
+ "through the recursive element"},
2013
+ };
2014
+ for (auto& c : cases) {
2015
+ LeptrisDocument d = leptris_parse_string(c.doc, strlen(c.doc), &st);
2016
+ ASSERT_NE(d, nullptr) << c.doc;
2017
+ EXPECT_EQ(leptris_rng_validate(rng, d), c.want)
2018
+ << c.why << " — doc: " << c.doc;
2019
+ leptris_document_free(d);
2020
+ }
2021
+ leptris_rng_free(rng);
2022
+ }
2023
+
1803
2024
  /* ---- leptris#2080: <data> content lexes through the XSD builtins -- */
1804
2025
 
1805
2026
  TEST(Rng2080Data, Base64BinaryLexes) {
@@ -2014,3 +2235,319 @@ TEST(Rng650InterleaveCombine, AddedElementMaySplitTheBaseSequence) {
2014
2235
  }
2015
2236
  leptris_rng_free(rng);
2016
2237
  }
2238
+
2239
+ /* ruby#650 follow-up: a zero-width member in the MIDDLE of the base
2240
+ * group (an optional element, an optional attribute, an empty repeat)
2241
+ * must advance the group's cursor, not finish the whole group. The
2242
+ * Metanorma shape is BibDataExtensionType: @schema-version?, doctype,
2243
+ * subdoctype?, flavor, ics*, ... interleaved with a flavor's ext
2244
+ * elements. Jing accepts every valid row below. */
2245
+ TEST(Rng650InterleaveCombine, ZeroWidthGroupMemberAdvancesTheCursor) {
2246
+ const char* schema =
2247
+ "<grammar xmlns=\"http://relaxng.org/ns/structure/1.0\">"
2248
+ "<start><element name=\"ext\"><ref name=\"Ext\"/></element></start>"
2249
+ "<define name=\"Ext\">"
2250
+ "<optional><attribute name=\"schema-version\"/></optional>"
2251
+ "<element name=\"doctype\"><text/></element>"
2252
+ "<optional><element name=\"subdoctype\"><text/></element></optional>"
2253
+ "<element name=\"flavor\"><text/></element>"
2254
+ "<zeroOrMore><element name=\"ics\"><text/></element></zeroOrMore>"
2255
+ "</define>"
2256
+ "<define name=\"Ext\" combine=\"interleave\">"
2257
+ "<optional><element name=\"ipn\"><text/></element></optional>"
2258
+ "<optional><element name=\"studyperiod\"><text/></element></optional>"
2259
+ "</define>"
2260
+ "</grammar>";
2261
+ LeptrisRelaxNG rng =
2262
+ leptris_rng_parse(schema, strlen(schema), nullptr);
2263
+ ASSERT_NE(rng, nullptr);
2264
+ LeptrisStatus st = LEPTRIS_OK;
2265
+ struct { const char* doc; int want; const char* why; } cases[] = {
2266
+ {"<ext><doctype/><flavor/><ipn/><studyperiod/></ext>", 1,
2267
+ "optional subdoctype and attribute skipped (metanorma-itu)"},
2268
+ {"<ext><doctype/><flavor/></ext>", 1, "base only, optionals skipped"},
2269
+ {"<ext><doctype/><ipn/><flavor/></ext>", 1,
2270
+ "added element where the skipped optional would sit"},
2271
+ {"<ext schema-version=\"v1\"><doctype/><subdoctype/><flavor/>"
2272
+ "<ics/><studyperiod/></ext>", 1, "every optional present"},
2273
+ {"<ext><doctype/><ipn/><subdoctype/><flavor/></ext>", 1,
2274
+ "added element before the optional member"},
2275
+ {"<ext><doctype/><ipn/></ext>", 0,
2276
+ "skipping the optional still requires flavor"},
2277
+ {"<ext><doctype/><flavor/><subdoctype/></ext>", 0,
2278
+ "base order is kept: subdoctype after flavor rejects"},
2279
+ };
2280
+ for (auto& c : cases) {
2281
+ LeptrisDocument d = leptris_parse_string(c.doc, strlen(c.doc), &st);
2282
+ ASSERT_NE(d, nullptr) << c.doc;
2283
+ EXPECT_EQ(leptris_rng_validate(rng, d), c.want)
2284
+ << c.why << " — doc: " << c.doc;
2285
+ leptris_document_free(d);
2286
+ }
2287
+ leptris_rng_free(rng);
2288
+ }
2289
+
2290
+ TEST(RngRegression, PositionErrorFindsTheElementUnderARoleDefine) {
2291
+ /* leptris#1704 in the shape real grammars use: the define is
2292
+ * named after the role (basicdoc "paragraph"), the element
2293
+ * pattern inside it is <p>. The misplaced <p> still gets its
2294
+ * attributes checked against that element pattern (Jing). */
2295
+ const char* sch = SCHEMA(
2296
+ "<start><element name='doc'>"
2297
+ "<element name='preface'><zeroOrMore><ref name='paragraph'/>"
2298
+ "</zeroOrMore></element>"
2299
+ "<element name='sections'><zeroOrMore><element name='clause'>"
2300
+ "<zeroOrMore><ref name='paragraph'/></zeroOrMore></element>"
2301
+ "</zeroOrMore></element>"
2302
+ "</element></start>"
2303
+ "<define name='paragraph'><element name='p'>"
2304
+ "<optional><attribute name='id'/></optional>"
2305
+ "<optional><attribute name='align'><choice>"
2306
+ "<value>left</value><value>right</value>"
2307
+ "</choice></attribute></optional><text/></element></define>"
2308
+ "<define name='paragraph-no-id'><element name='p'>"
2309
+ "<text/></element></define>");
2310
+ LeptrisStatus st = LEPTRIS_OK;
2311
+ LeptrisRelaxNG rng = leptris_rng_parse(sch, strlen(sch), &st);
2312
+ ASSERT_EQ(st, LEPTRIS_OK) << leptris_last_error();
2313
+ ASSERT_NE(rng, nullptr);
2314
+ const char doc[] =
2315
+ "<doc><preface/><sections><clause><p>a</p></clause>"
2316
+ "<p align='mid-air'>b</p></sections></doc>";
2317
+ LeptrisDocument d = leptris_parse_string(doc, strlen(doc), NULL);
2318
+ ASSERT_NE(d, nullptr);
2319
+ EXPECT_EQ(leptris_rng_validate(rng, d), 0);
2320
+ const LeptrisRngErrorRecord* rep = NULL;
2321
+ size_t n = leptris_rng_error_report(rng, &rep);
2322
+ ASSERT_GE(n, 2u) << "expected position AND attribute errors";
2323
+ EXPECT_NE(strstr(rep[0].message, "element \"p\" not allowed"),
2324
+ nullptr) << rep[0].message;
2325
+ EXPECT_NE(strstr(rep[1].message,
2326
+ "value of attribute \"align\" is invalid; must be equal to "
2327
+ "\"left\" or \"right\""), nullptr) << rep[1].message;
2328
+ for (size_t i = 0; i < n; i++)
2329
+ EXPECT_EQ(strstr(rep[i].message, "no attributes allowed"),
2330
+ nullptr) << rep[i].message;
2331
+ leptris_document_free(d);
2332
+ leptris_rng_free(rng);
2333
+ }
2334
+
2335
+ /* ---- leptris#2093: combine="interleave" interleaves INTO a group ---
2336
+ * The merged define is interleave(group(base...), group(added...))
2337
+ * (RELAX NG §4.17). Interleave is a shuffle of the branch sequences:
2338
+ * a group branch keeps its own order, but members of the other
2339
+ * branch may sit between its members. Regression since 1.9.428. */
2340
+
2341
+ /* Validate; collect the joined diagnostic messages into *msgs. */
2342
+ static int rng2093_check(LeptrisRelaxNG rng, const char* doc,
2343
+ std::string* msgs) {
2344
+ LeptrisStatus st = LEPTRIS_OK;
2345
+ LeptrisDocument d = leptris_parse_string(doc, strlen(doc), &st);
2346
+ if (!d) return -2;
2347
+ int ok = leptris_rng_validate(rng, d);
2348
+ msgs->clear();
2349
+ const LeptrisRngErrorRecord* rep = NULL;
2350
+ size_t n = leptris_rng_error_report(rng, &rep);
2351
+ for (size_t i = 0; i < n; i++) {
2352
+ if (i) *msgs += " | ";
2353
+ *msgs += rep[i].message ? rep[i].message : "";
2354
+ }
2355
+ leptris_document_free(d);
2356
+ return ok;
2357
+ }
2358
+
2359
+ TEST(Rng2093InterleaveIntoGroup, AddedBodyGoesBetweenBaseMembers) {
2360
+ const char* schema =
2361
+ "<grammar xmlns=\"http://relaxng.org/ns/structure/1.0\">"
2362
+ "<start><element name=\"root\"><ref name=\"content\"/></element></start>"
2363
+ "<define name=\"content\">"
2364
+ "<element name=\"a\"><empty/></element>"
2365
+ "<element name=\"b\"><empty/></element>"
2366
+ "</define>"
2367
+ "<define name=\"content\" combine=\"interleave\">"
2368
+ "<element name=\"c\"><empty/></element>"
2369
+ "</define>"
2370
+ "</grammar>";
2371
+ LeptrisRelaxNG rng = leptris_rng_parse(schema, strlen(schema), nullptr);
2372
+ ASSERT_NE(rng, nullptr);
2373
+ struct { const char* doc; int want; } cases[] = {
2374
+ {"<root><a/><b/><c/></root>", 1},
2375
+ {"<root><c/><a/><b/></root>", 1},
2376
+ {"<root><a/><c/><b/></root>", 1}, /* the #2093 regression */
2377
+ {"<root><c/><b/><a/></root>", 0}, /* a precedes b */
2378
+ {"<root><b/><a/><c/></root>", 0},
2379
+ {"<root><a/><b/></root>", 0}, /* c is required */
2380
+ {"<root><a/><c/><c/><b/></root>", 0},
2381
+ };
2382
+ std::string msgs;
2383
+ for (auto& c : cases) {
2384
+ EXPECT_EQ(rng2093_check(rng, c.doc, &msgs), c.want)
2385
+ << c.doc << " — " << msgs;
2386
+ if (c.want == 1) EXPECT_EQ(msgs, "") << c.doc;
2387
+ }
2388
+ EXPECT_EQ(rng2093_check(rng, "<root><c/><b/><a/></root>", &msgs), 0);
2389
+ EXPECT_NE(msgs.find("element \"b\""), std::string::npos) << msgs;
2390
+ leptris_rng_free(rng);
2391
+ }
2392
+
2393
+ /* ruby#650 shape: Ext = doctype, flavor, ics* |= interleave price-code? */
2394
+ static const char* const k2093Valid[] = {
2395
+ "<ext><price-code/><doctype/><flavor/><ics/><ics/></ext>",
2396
+ "<ext><doctype/><price-code/><flavor/><ics/><ics/></ext>",
2397
+ "<ext><doctype/><flavor/><price-code/><ics/><ics/></ext>",
2398
+ "<ext><doctype/><flavor/><ics/><price-code/><ics/></ext>",
2399
+ "<ext><doctype/><flavor/><ics/><ics/><price-code/></ext>",
2400
+ "<ext><doctype/><flavor/></ext>",
2401
+ };
2402
+ static const char* const k2093Invalid[] = {
2403
+ "<ext><flavor/><doctype/><price-code/></ext>",
2404
+ "<ext><doctype/><price-code/><flavor/><price-code/></ext>",
2405
+ "<ext><doctype/><ics/><flavor/></ext>",
2406
+ };
2407
+
2408
+ static void rng2093_shape(LeptrisRelaxNG rng) {
2409
+ std::string msgs;
2410
+ for (const char* doc : k2093Valid) {
2411
+ EXPECT_EQ(rng2093_check(rng, doc, &msgs), 1) << doc << " — " << msgs;
2412
+ EXPECT_EQ(msgs, "") << doc;
2413
+ }
2414
+ for (const char* doc : k2093Invalid)
2415
+ EXPECT_EQ(rng2093_check(rng, doc, &msgs), 0) << doc;
2416
+ }
2417
+
2418
+ TEST(Rng2093InterleaveIntoGroup, Ruby650InlineShape) {
2419
+ const char* schema =
2420
+ "<grammar xmlns=\"http://relaxng.org/ns/structure/1.0\">"
2421
+ "<start><element name=\"ext\"><ref name=\"Ext\"/></element></start>"
2422
+ "<define name=\"Ext\">"
2423
+ "<element name=\"doctype\"><empty/></element>"
2424
+ "<element name=\"flavor\"><empty/></element>"
2425
+ "<zeroOrMore><element name=\"ics\"><empty/></element></zeroOrMore>"
2426
+ "</define>"
2427
+ "<define name=\"Ext\" combine=\"interleave\">"
2428
+ "<optional><element name=\"price-code\"><empty/></element></optional>"
2429
+ "</define>"
2430
+ "</grammar>";
2431
+ LeptrisRelaxNG rng = leptris_rng_parse(schema, strlen(schema), nullptr);
2432
+ ASSERT_NE(rng, nullptr);
2433
+ rng2093_shape(rng);
2434
+ leptris_rng_free(rng);
2435
+ }
2436
+
2437
+ TEST(Rng2093InterleaveIntoGroup, Ruby650IncludeForm) {
2438
+ LeptrisRelaxNG rng = parse_file("i2093-ext.rng");
2439
+ ASSERT_NE(rng, nullptr);
2440
+ rng2093_shape(rng);
2441
+ leptris_rng_free(rng);
2442
+ }
2443
+
2444
+ TEST(Rng2093InterleaveIntoGroup, WindowStopsWhereTheInterleaveEnds) {
2445
+ /* An interleave followed by a sibling (or the next pass of a
2446
+ * repeat) that matches one of its names: the interleave must
2447
+ * leave those children alone. */
2448
+ struct { const char* content; const char* doc; int want; } cases[] = {
2449
+ {"<oneOrMore><interleave><element name='a'><empty/></element>"
2450
+ "<element name='b'><empty/></element></interleave></oneOrMore>",
2451
+ "<r><a/><b/><b/><a/></r>", 1},
2452
+ {"<oneOrMore><interleave><element name='a'><empty/></element>"
2453
+ "<element name='b'><empty/></element></interleave></oneOrMore>",
2454
+ "<r><b/><a/><a/><b/><a/><b/></r>", 1},
2455
+ {"<interleave><element name='a'><empty/></element>"
2456
+ "<element name='b'><empty/></element></interleave>"
2457
+ "<element name='a'><empty/></element>",
2458
+ "<r><a/><b/><a/></r>", 1},
2459
+ /* shuffle needed AND a following sibling of the same name */
2460
+ {"<interleave><group><element name='a'><empty/></element>"
2461
+ "<element name='b'><empty/></element></group>"
2462
+ "<element name='c'><empty/></element></interleave>"
2463
+ "<element name='a'><empty/></element>",
2464
+ "<r><a/><c/><b/><a/></r>", 1},
2465
+ {"<oneOrMore><interleave><group><element name='a'><empty/></element>"
2466
+ "<element name='b'><empty/></element></group>"
2467
+ "<element name='c'><empty/></element></interleave></oneOrMore>",
2468
+ "<r><a/><c/><b/><a/><c/><b/></r>", 1},
2469
+ {"<oneOrMore><interleave><group><element name='a'><empty/></element>"
2470
+ "<element name='b'><empty/></element></group>"
2471
+ "<element name='c'><empty/></element></interleave></oneOrMore>",
2472
+ "<r><a/><c/><a/><b/><c/><b/></r>", 0},
2473
+ };
2474
+ for (auto& c : cases) {
2475
+ std::string schema =
2476
+ std::string("<grammar xmlns='" RNGNS "'><start>"
2477
+ "<element name='r'>") +
2478
+ c.content + "</element></start></grammar>";
2479
+ LeptrisRelaxNG rng =
2480
+ leptris_rng_parse(schema.c_str(), schema.size(), nullptr);
2481
+ ASSERT_NE(rng, nullptr) << c.content;
2482
+ std::string msgs;
2483
+ EXPECT_EQ(rng2093_check(rng, c.doc, &msgs), c.want)
2484
+ << c.content << " / " << c.doc << " — " << msgs;
2485
+ leptris_rng_free(rng);
2486
+ }
2487
+ }
2488
+
2489
+ static std::string rng2093_repeat(const char* unit, int times) {
2490
+ std::string s;
2491
+ for (int i = 0; i < times; i++) s += unit;
2492
+ return s;
2493
+ }
2494
+
2495
+ TEST(Rng2093InterleaveIntoGroup, RepeatBranchesBeforeASiblingStayInBudget) {
2496
+ /* interleave(a*, b*) followed by a sibling never reaches the
2497
+ * "complete at n" early exit: unmemoized full enumeration spent
2498
+ * its whole 200000-step budget already at 10 pairs and answered
2499
+ * only because the search order found the furthest end first.
2500
+ * Memoized, 31 pairs take ~200 steps. Kept under 64 children:
2501
+ * element_ok reads at most 64 element children. */
2502
+ const char* sch = SCHEMA(
2503
+ "<start><element name='r'><interleave>"
2504
+ "<zeroOrMore><element name='a'><empty/></element></zeroOrMore>"
2505
+ "<zeroOrMore><element name='b'><empty/></element></zeroOrMore>"
2506
+ "</interleave><element name='c'><empty/></element>"
2507
+ "</element></start>");
2508
+ LeptrisRelaxNG rng = leptris_rng_parse(sch, strlen(sch), nullptr);
2509
+ ASSERT_NE(rng, nullptr);
2510
+ std::string msgs;
2511
+ for (int pairs : {5, 20, 31}) {
2512
+ std::string doc = "<r>" + rng2093_repeat("<a/><b/>", pairs) +
2513
+ "<c/></r>";
2514
+ EXPECT_EQ(rng2093_check(rng, doc.c_str(), &msgs), 1)
2515
+ << pairs << " pairs — " << msgs;
2516
+ doc = "<r>" + rng2093_repeat("<a/><b/>", pairs) + "<c/><a/></r>";
2517
+ EXPECT_EQ(rng2093_check(rng, doc.c_str(), &msgs), 0)
2518
+ << pairs << " pairs + trailing a";
2519
+ }
2520
+ leptris_rng_free(rng);
2521
+ }
2522
+
2523
+ TEST(Rng2093InterleaveIntoGroup, DiagnosisKeepsTheGroupBranchTail) {
2524
+ /* Invalid for an unrelated reason (a stray element at the end).
2525
+ * The diagnosis must name only the stray element: after doctype
2526
+ * consumes, the base group's tail (flavor, ics*) survives in the
2527
+ * interleave state — dropping it reported the correctly placed
2528
+ * flavor as "not allowed here". */
2529
+ const char* schema =
2530
+ "<grammar xmlns=\"http://relaxng.org/ns/structure/1.0\">"
2531
+ "<start><element name=\"ext\"><ref name=\"Ext\"/></element></start>"
2532
+ "<define name=\"Ext\">"
2533
+ "<element name=\"doctype\"><empty/></element>"
2534
+ "<element name=\"flavor\"><empty/></element>"
2535
+ "<zeroOrMore><element name=\"ics\"><empty/></element></zeroOrMore>"
2536
+ "</define>"
2537
+ "<define name=\"Ext\" combine=\"interleave\">"
2538
+ "<optional><element name=\"price-code\"><empty/></element></optional>"
2539
+ "</define>"
2540
+ "</grammar>";
2541
+ LeptrisRelaxNG rng = leptris_rng_parse(schema, strlen(schema), nullptr);
2542
+ ASSERT_NE(rng, nullptr);
2543
+ std::string msgs;
2544
+ const char* doc =
2545
+ "<ext><doctype/><price-code/><flavor/><ics/><bogus/></ext>";
2546
+ EXPECT_EQ(rng2093_check(rng, doc, &msgs), 0);
2547
+ EXPECT_NE(msgs.find("\"bogus\""), std::string::npos) << msgs;
2548
+ EXPECT_EQ(msgs.find("element \"flavor\" not allowed"), std::string::npos)
2549
+ << msgs;
2550
+ EXPECT_EQ(msgs.find("element \"ics\" not allowed"), std::string::npos)
2551
+ << msgs;
2552
+ leptris_rng_free(rng);
2553
+ }
@@ -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.429",
4
+ "version": "1.9.430",
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.429.0
4
+ version: 1.9.430.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-19 00:00:00.000000000 Z
11
+ date: 2026-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -913,6 +913,7 @@ files:
913
913
  - vendor-src/libleptris/test/fuzz/corpus/gen/gen_0038.xsl
914
914
  - vendor-src/libleptris/test/fuzz/corpus/gen/gen_0039.xsl
915
915
  - vendor-src/libleptris/test/fuzz/corpus/html_foreign_cdata_short_opener.bin
916
+ - vendor-src/libleptris/test/fuzz/corpus/html_reconstruction_nest_min.bin
916
917
  - vendor-src/libleptris/test/fuzz/corpus/html_tree_amplification_timeout.bin
917
918
  - vendor-src/libleptris/test/fuzz/corpus/seed1
918
919
  - vendor-src/libleptris/test/fuzz/corpus/seed2
@@ -1032,6 +1033,8 @@ files:
1032
1033
  - vendor-src/libleptris/test/rng/include-cases/dup-inc-top.rng
1033
1034
  - vendor-src/libleptris/test/rng/include-cases/ext-lib.rng
1034
1035
  - vendor-src/libleptris/test/rng/include-cases/ext-main.rng
1036
+ - vendor-src/libleptris/test/rng/include-cases/i2093-base.rng
1037
+ - vendor-src/libleptris/test/rng/include-cases/i2093-ext.rng
1035
1038
  - vendor-src/libleptris/test/rng/include-cases/lib.rng
1036
1039
  - vendor-src/libleptris/test/rng/include-cases/lib2.rng
1037
1040
  - vendor-src/libleptris/test/rng/include-cases/main.rng