leptris 1.9.402.0-arm-linux → 1.9.403.0-arm-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3104ffdc2a91c3468bdc740b209762b1682a30b0642b5da324b62426f3f522e6
4
- data.tar.gz: 5572dd6386156117e5ef2a3887c7e80d601e15d5e2c5cd7baeff5f6cd1543215
3
+ metadata.gz: 8d437d99c3ca2fd8c8ceb700ded511bfb862251c0eddb9f39d824e69960742a8
4
+ data.tar.gz: 7ea22b9ffa53ec0153711716157af630cb32d9e82e73b34cb59d0d69318147c7
5
5
  SHA512:
6
- metadata.gz: 6dfbfd98f2c83a606c8b62b547783900516b83327ef04a69805284ba4f255e63d602060f84c143befda6323227dba749f6c60c27d138dec6ada6efdde9b4ae5c
7
- data.tar.gz: f3c28c087dbf33c6557f40608788cd49c35fe3f30b89b8369f6839a74f7aa9c7ec097652d481d8dcf2d53b66f4329c80f3a300833da0d5487e1d0482bb3772e6
6
+ metadata.gz: f067598fa8743421010f38b56e91e7e292af4f443687a9695a712d126eb12ad92a96da3f8c8f94e0f9364deaf7b610964228f31ab1fd7b1a49689603aad23162
7
+ data.tar.gz: dbafef1c715fb7a800b7cccd20ccab3bfff8b42ae31f03dbe023bc36dc3ff4732857582e8ccb6709cc820a202ca74f27fbf4149fe9abc8ffa4c1318b026daf3d
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.402"
11
+ LIBLEPTRIS_VERSION = "1.9.403"
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.402.0"
4
+ VERSION = "1.9.403.0"
5
5
  end
data/lib/libleptris.so CHANGED
Binary file
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.402
4
+ - libleptris v1.9.403
5
5
  - utf8proc v2.11.0
6
6
 
7
7
  Rebuild by hand:
@@ -1,5 +1,20 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.9.403] - 2026-11-03
4
+
5
+ ### Fixed
6
+
7
+ - temporal enumeration compares by value, not lexically (leptris-rs#27) (xsd)
8
+ - whiteSpace=collapse covers every non-string builtin (leptris-rs#29, elemZ002) (xsd)
9
+ - a nilled element must have empty content - the model is not applied (leptris-rs#26) (xsd)
10
+ - empty content satisfies a fixed value; -0 lexes for nonNegativeInteger (leptris-rs#25/#28) (xsd)
11
+ - subtraction root cause, XSD \w excludes '_', empty content model (leptris#1936 reF39/reZ002/p2) (rng,xsd)
12
+ - in-class builtin merge carries uni ranges and XML pins (leptris#1936 reZ003-006) (rng)
13
+ - {n,} unbounded, empty branches, and REP over nullable bodies (leptris#1936 reC57/reE10/reD3) (rng)
14
+ - regex-tail conformance - pattern disjunction, class grammar, empty content (leptris#1936 p16/reG) (xsd)
15
+
16
+
17
+
3
18
  ## [1.9.402] - 2026-11-02
4
19
 
5
20
  ### Fixed
@@ -3,7 +3,7 @@
3
3
  cmake_minimum_required(VERSION 3.20)
4
4
 
5
5
  project(leptris
6
- VERSION 1.9.402
6
+ VERSION 1.9.403
7
7
  DESCRIPTION "Fast XML parser and XPath evaluator in pure C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -36,6 +36,8 @@ enum {
36
36
  RRE_CAT,
37
37
  RRE_ALT,
38
38
  RRE_REP,
39
+ RRE_EMPTY, /* F.1 [2]: a branch of zero pieces matches only "" */
40
+ RRE_MINPOS, /* count-loop sentinel: iteration must consume */
39
41
  };
40
42
 
41
43
  typedef struct RreNode {
@@ -60,12 +62,6 @@ typedef struct RreNode {
60
62
  * complement of punctuation/separators/controls, not the union
61
63
  * of letters (Sm/Sc/Sk are word chars per the suite). */
62
64
  unsigned cat_neg;
63
- /* cat_strict (moxml#464): a class-internal COMPLEMENT builtin
64
- * ([\I], [\D]) needs bitmap AND cats to agree — the normal
65
- * union can't express "not in the set" once the bitmap holds
66
- * the complement's high bytes (U+00AA is in ~ASCII-bits but
67
- * excluded by the category). */
68
- unsigned cat_strict;
69
65
  /* XSD charClassSub: the bracketed subtrahend (moxml#464). The
70
66
  * node is consulted at match time so its ranges, blocks and
71
67
  * categories all subtract — the old byte-bitmap merge ignored
@@ -135,11 +131,15 @@ static void cls_add_builtin(RreNode* n, char c) {
135
131
  * Me are all word chars (the suite's reV rows: U+2044,
136
132
  * U+20A0, U+00B2, U+20DD never match \W). The ASCII-only
137
133
  * form made \W accept every non-ASCII non-punct char
138
- * (#1936 reV family). */
134
+ * (#1936 reV family). '_' (Pc) is PUNCTUATION per the
135
+ * table's \p{P} exclusion — NOT a word char (reZ002:
136
+ * first_last fails [\w\-\.]+@.*; Perl's \w includes it,
137
+ * XSD's does not). */
139
138
  for (int i = 'a'; i <= 'z'; i++) cls_add(n, (unsigned char)i);
140
139
  for (int i = 'A'; i <= 'Z'; i++) cls_add(n, (unsigned char)i);
141
140
  for (int i = '0'; i <= '9'; i++) cls_add(n, (unsigned char)i);
142
- cls_add(n, '_');
141
+ /* Pc rides the cat_mask below (the byte bitmap cannot
142
+ * express "excluded" once the complement negates) */
143
143
  #if defined(LEPTRIS_HAS_UTF8PROC)
144
144
  n->cat_set = 1;
145
145
  n->cat_neg = 1;
@@ -174,6 +174,13 @@ static void cls_add_builtin(RreNode* n, char c) {
174
174
  for (int i = 'A'; i <= 'Z'; i++) cls_add(n, (unsigned char)i);
175
175
  cls_add(n, '_');
176
176
  cls_add(n, ':');
177
+ /* XML 1.0 lists U+212E ESTIMATE SIGN explicitly in the
178
+ * Letter production (So in modern tables) — reZ005v */
179
+ if (n->uni_n < 4) {
180
+ n->uni_lo[n->uni_n] = 0x212E;
181
+ n->uni_hi[n->uni_n] = 0x212E;
182
+ n->uni_n++;
183
+ }
177
184
  #if defined(LEPTRIS_HAS_UTF8PROC)
178
185
  /* letters above the bitmap: the old 0x80-0xFF blanket
179
186
  * also accepted symbols like U+00D7 (moxml#464) */
@@ -196,6 +203,36 @@ static void cls_add_builtin(RreNode* n, char c) {
196
203
  cls_add(n, ':');
197
204
  cls_add(n, '.');
198
205
  cls_add(n, '-');
206
+ /* XML 1.0 vintage pins: U+212E (BaseChar, reZ005v),
207
+ * U+06DD (CombiningChar: Mn in Unicode 3.1, demoted to
208
+ * Cf in 4.0.1 — reZ006v), and U+00B7/U+0387 (the
209
+ * Extender production's explicit Po members — reZ006v),
210
+ * the same vintage-demotion family as the \d legacy-Nd
211
+ * pin */
212
+ if (n->uni_n < 4) {
213
+ n->uni_lo[n->uni_n] = 0x212E;
214
+ n->uni_hi[n->uni_n] = 0x212E;
215
+ n->uni_n++;
216
+ }
217
+ if (n->uni_n < 4) {
218
+ n->uni_lo[n->uni_n] = 0x06DD;
219
+ n->uni_hi[n->uni_n] = 0x06DD;
220
+ n->uni_n++;
221
+ }
222
+ /* U+06DE: Mn in Unicode 3.1 -> So in 4.0.1 (reZ006v) */
223
+ if (n->uni_n < 4) {
224
+ n->uni_lo[n->uni_n] = 0x06DE;
225
+ n->uni_hi[n->uni_n] = 0x06DE;
226
+ n->uni_n++;
227
+ }
228
+ /* 0xB7 sits in the BYTE bitmap (uni ranges are only
229
+ * consulted above 0x100) */
230
+ cls_add(n, 0xB7);
231
+ if (n->uni_n < 4) {
232
+ n->uni_lo[n->uni_n] = 0x0387;
233
+ n->uni_hi[n->uni_n] = 0x0387;
234
+ n->uni_n++;
235
+ }
199
236
  #if defined(LEPTRIS_HAS_UTF8PROC)
200
237
  n->cat_set = 1;
201
238
  n->cat_mask = (1u << UTF8PROC_CATEGORY_LU) |
@@ -290,16 +327,22 @@ static int cls_has_cp(const RreNode* n, unsigned cp) {
290
327
  (1u << utf8proc_get_property((utf8proc_int32_t)cp)
291
328
  ->category)) != 0;
292
329
  if (n->cat_neg) c = !c;
293
- hit = n->cat_strict ? (hit && c) : (hit || c);
330
+ hit = hit || c;
294
331
  }
295
332
  #else
296
333
  (void)0;
297
334
  #endif
298
335
  if (n->negm)
299
336
  hit = hit || !cls_has_cp(n->negm, cp);
337
+ /* charClassSub [16] applies to the GROUP's set: the neg flip
338
+ * (negCharGroup) composes BEFORE the subtraction — for
339
+ * [^cde-[ag]] the complement is the minuend, so 'a'/'g' are
340
+ * excluded even though they sit outside the raw bitmap
341
+ * (RegexTest_430). */
342
+ if (n->neg) hit = !hit;
300
343
  if (hit && n->subtract)
301
344
  hit = !cls_has_cp(n->subtract, cp);
302
- return n->neg ? !hit : hit;
345
+ return hit;
303
346
  }
304
347
 
305
348
  /* Strict UTF-8 decode at s (text is well-formed UTF-8; malformed
@@ -585,8 +628,11 @@ static RreNode* parse_class(RreParser* ps) {
585
628
  ps->p++;
586
629
  }
587
630
  int first = 1;
631
+ int member_ord = 0;
588
632
  while (*ps->p && (*ps->p != ']' || first)) {
589
633
  first = 0;
634
+ int is_first_member = (member_ord == 0);
635
+ member_ord++;
590
636
  if (*ps->p == '\\' && (ps->p[1] == 'p' || ps->p[1] == 'P') &&
591
637
  ps->p[2] == '{') {
592
638
  /* XSD property classes for the Latin-1 byte world —
@@ -680,49 +726,114 @@ static RreNode* parse_class(RreParser* ps) {
680
726
  node_free(n);
681
727
  return NULL;
682
728
  }
683
- cls_add_builtin(tmp, e);
729
+ /* cls_add_builtin implements the LOWERCASE spellings;
730
+ * the uppercase forms negate via negm (reG21/reG23:
731
+ * [\D]+ must reject '1' — the old path passed 'D'
732
+ * raw, built an empty member set, and the complement
733
+ * memset accepted every byte). */
734
+ char pos = (char)((e >= 'A' && e <= 'Z')
735
+ ? e - 'A' + 'a' : e);
736
+ cls_add_builtin(tmp, pos);
684
737
  int neg_b = e == 'D' || e == 'W' || e == 'S' ||
685
738
  e == 'I' || e == 'C';
739
+ if (neg_b) {
740
+ /* Negated built-in: the class gains the
741
+ * COMPLEMENT of the member — the negm slot
742
+ * (hit || !cls_has_cp(negm)) unions a flipped
743
+ * sub-class, codepoint-exact across bytes, uni
744
+ * ranges (the \d legacy-Nd pin stays excluded
745
+ * from \D) and categories (\W flips the \w
746
+ * complement form back to P|Z|C). A second
747
+ * negated member degrades to the positive
748
+ * spelling (single negm slot, as with \P). */
749
+ if (!n->negm) {
750
+ n->negm = tmp;
751
+ continue;
752
+ }
753
+ #if defined(LEPTRIS_HAS_UTF8PROC)
754
+ if (tmp->cat_set) {
755
+ n->cat_set = 1;
756
+ n->cat_mask |= tmp->cat_mask;
757
+ }
758
+ #endif
759
+ for (int i = 0; i < 256; i++)
760
+ if ((tmp->cls[i >> 3] >> (i & 7)) & 1)
761
+ cls_add(n, (unsigned char)i);
762
+ node_free(tmp);
763
+ continue;
764
+ }
686
765
  #if defined(LEPTRIS_HAS_UTF8PROC)
687
- if (!neg_b && tmp->cat_set) {
766
+ if (tmp->cat_set) {
688
767
  n->cat_set = 1;
689
768
  n->cat_mask |= tmp->cat_mask;
690
- } else if (neg_b && tmp->cat_set && !n->cat_set) {
691
- n->cat_set = 1;
692
- n->cat_strict = 1;
693
- n->cat_mask = (~tmp->cat_mask) & 0x7FFFFFFFu;
769
+ /* \w rides the COMPLEMENT form: the mask lists
770
+ * P|Z|C and the verdict negates (reZ003-006:
771
+ * [\w] accepts Sm/No/letters, rejects P/Z/C) */
772
+ if (tmp->cat_neg) n->cat_neg = 1;
694
773
  }
695
774
  #endif
775
+ /* the builtin's UNI ranges ride too — [\d] must keep
776
+ * the legacy-Nd pin U+1369-1371 (reZ004v) */
777
+ for (int i = 0; i < tmp->uni_n && n->uni_n < 4; i++) {
778
+ n->uni_lo[n->uni_n] = tmp->uni_lo[i];
779
+ n->uni_hi[n->uni_n] = tmp->uni_hi[i];
780
+ n->uni_n++;
781
+ }
696
782
  for (int i = 0; i < 256; i++)
697
- if (((tmp->cls[i >> 3] >> (i & 7)) & 1) ==
698
- (neg_b ? 0 : 1))
783
+ if ((tmp->cls[i >> 3] >> (i & 7)) & 1)
699
784
  cls_add(n, (unsigned char)i);
700
- if (neg_b) {
701
- /* Negated built-in: everything except the set. */
702
- memset(n->cls, 0xff, sizeof(n->cls));
703
- for (int i = 0; i < 256; i++)
704
- if ((tmp->cls[i >> 3] >> (i & 7)) & 1)
705
- n->cls[i >> 3] &=
706
- (unsigned char)~(1u << (i & 7));
707
- }
708
785
  node_free(tmp);
709
786
  continue;
710
787
  }
711
788
  /* XSD singleCharEsc covers the control escapes too
712
789
  * (the OPC ST_ContentType pattern uses \t) —
713
- * leptris-ruby#434. */
714
- if (e == 't') { cls_add(n, '\t'); continue; }
715
- if (e == 'n') { cls_add(n, '\n'); continue; }
716
- if (e == 'r') { cls_add(n, '\r'); continue; }
717
- cls_add(n, (unsigned char)e);
718
- continue;
790
+ * leptris-ruby#434. Greedy seRange [18]: a singleCharEsc
791
+ * may open a range ([\\-\\{^], reG17: range \..{ union
792
+ * ^) — the end must be a charOrEsc and NOT `\\`/`[` per
793
+ * the seRange bullets. */
794
+ {
795
+ unsigned scp = (e == 't') ? (unsigned)'\t'
796
+ : (e == 'n') ? (unsigned)'\n'
797
+ : (e == 'r') ? (unsigned)'\r'
798
+ : (unsigned char)e;
799
+ /* `-[` is charClassSub, not a range toward '[' (the
800
+ * subtraction branch fires at the member loop) */
801
+ if (*ps->p == '-' && ps->p[1] && ps->p[1] != ']' &&
802
+ ps->p[1] != '[') {
803
+ ps->p++;
804
+ int hi_esc = (*ps->p == '\\');
805
+ unsigned hi = 0;
806
+ if (!cls_read_cp(ps, &hi) || hi < scp ||
807
+ hi == 0x5B || (hi_esc && hi == 0x5C)) {
808
+ node_free(n);
809
+ ps->bad = 1;
810
+ return NULL;
811
+ }
812
+ if (scp < 0x100 && hi < 0x100) {
813
+ for (unsigned int i = scp; i <= hi; i++)
814
+ cls_add(n, (unsigned char)i);
815
+ } else if (n->uni_n < 4) {
816
+ n->uni_lo[n->uni_n] = scp;
817
+ n->uni_hi[n->uni_n] = hi;
818
+ n->uni_n++;
819
+ }
820
+ continue;
821
+ }
822
+ cls_add_cp(n, scp);
823
+ continue;
824
+ }
719
825
  }
720
826
  /* XSD charClassSub: `[ A - [ B ] ]` — the '-' followed by
721
827
  * '[' subtracts the bracketed class (leptris-ruby#434, the
722
828
  * OPC ST_ContentType shape). The subtraction is the last
723
829
  * member of the class. */
724
830
  if (*ps->p == '-' && ps->p[1] == '[') {
725
- ps->p++;
831
+ /* skip BOTH '-' and '[': parse_class expects to be
832
+ * entered past the opening bracket (the atom path does
833
+ * the same) — skipping only '-' parsed the subtrahend's
834
+ * '[' as a literal member and dropped a leading '^'
835
+ * (reF39: [a-z-[^a]] must be {a}) */
836
+ ps->p += 2;
726
837
  RreNode* sub = parse_class(ps);
727
838
  if (!sub) {
728
839
  node_free(n);
@@ -744,10 +855,15 @@ static RreNode* parse_class(RreParser* ps) {
744
855
  ps->bad = 1;
745
856
  return NULL;
746
857
  }
747
- if (*ps->p == '-' && ps->p[1] && ps->p[1] != ']') {
858
+ /* the same `-[` precedence: a single-char member followed
859
+ * by subtraction is charClassSub, not a range toward '[' */
860
+ if (*ps->p == '-' && ps->p[1] && ps->p[1] != ']' &&
861
+ ps->p[1] != '[') {
748
862
  ps->p++;
863
+ int hi_esc = (*ps->p == '\\');
749
864
  unsigned hi = 0;
750
- if (!cls_read_cp(ps, &hi) || hi < lo) {
865
+ if (!cls_read_cp(ps, &hi) || hi < lo ||
866
+ hi == 0x5B || (hi_esc && hi == 0x5C)) {
751
867
  node_free(n);
752
868
  ps->bad = 1;
753
869
  return NULL;
@@ -761,6 +877,15 @@ static RreNode* parse_class(RreParser* ps) {
761
877
  n->uni_n++;
762
878
  }
763
879
  } else {
880
+ /* F.1 [17]/[22]: a standalone '-' is a member only at
881
+ * the BEGINNING or END of the group — after a completed
882
+ * member with a following non-']' char it is a grammar
883
+ * error (reG26-33/reH19: [a-c-1-4x-z-7-9], [a-a-x-x]) */
884
+ if (lo == '-' && !is_first_member && *ps->p != ']') {
885
+ node_free(n);
886
+ ps->bad = 1;
887
+ return NULL;
888
+ }
764
889
  cls_add_cp(n, lo);
765
890
  }
766
891
  }
@@ -918,12 +1043,14 @@ static RreNode* parse_piece(RreParser* ps) {
918
1043
  } else if (*ps->p == '{') {
919
1044
  const char* q = ps->p + 1;
920
1045
  int l = -1, h = -1;
1046
+ int saw_comma = 0;
921
1047
  char* end = NULL;
922
1048
  long v = strtol(q, &end, 10);
923
1049
  if (end > q) {
924
1050
  l = (int)v;
925
1051
  q = end;
926
1052
  if (*q == ',') {
1053
+ saw_comma = 1;
927
1054
  q++;
928
1055
  if (*q == '}') {
929
1056
  h = -1;
@@ -937,8 +1064,11 @@ static RreNode* parse_piece(RreParser* ps) {
937
1064
  }
938
1065
  /* {n} with no comma is EXACT — h must be l, not the
939
1066
  * -1 "unbounded" sentinel. The old code left h = -1,
940
- * so [A-Z]{3} matched ABCD (open-ended {3,}). */
941
- if (*q != ',' && h == -1) h = l;
1067
+ * so [A-Z]{3} matched ABCD (open-ended {3,}). {n,}
1068
+ * (comma seen) stays unbounded — the old exact-fix
1069
+ * checked *q != ',' AFTER the comma was consumed, so
1070
+ * a{2,} collapsed to {2,2} and never matched 'aaa'. */
1071
+ if (!saw_comma && h == -1) h = l;
942
1072
  if (*q == '}' && l >= 0 && (h == -1 || h >= l)) {
943
1073
  lo = l;
944
1074
  hi = h;
@@ -959,6 +1089,12 @@ static RreNode* parse_piece(RreParser* ps) {
959
1089
  }
960
1090
 
961
1091
  static RreNode* parse_cat(RreParser* ps) {
1092
+ /* F.1 [2]: branch ::= piece* — ZERO pieces is a legal empty
1093
+ * branch matching only "" (reE10: the pattern "|" is valid). */
1094
+ if (!*ps->p || *ps->p == '|' || *ps->p == ')') {
1095
+ RreNode* e = node_new(RRE_EMPTY);
1096
+ return e;
1097
+ }
962
1098
  RreNode* first = parse_piece(ps);
963
1099
  if (!first) return NULL;
964
1100
  if (!*ps->p || *ps->p == '|' || *ps->p == ')') return first;
@@ -1014,6 +1150,16 @@ static const char* rre_run(const RreCont* k, const char* s) {
1014
1150
  static const char* rre_match(RreNode* n, const char* s,
1015
1151
  const RreCont* k) {
1016
1152
  switch (n->kind) {
1153
+ case RRE_EMPTY:
1154
+ return rre_run(k, s);
1155
+ case RRE_MINPOS: {
1156
+ /* the stored start of the iteration: an empty match is
1157
+ * rejected so the caller's ALT falls through to
1158
+ * alternatives that progress (reD3-6) */
1159
+ const char* iter_start = (const char*)n->l;
1160
+ if (s != iter_start) return rre_run(k, s);
1161
+ return NULL;
1162
+ }
1017
1163
  case RRE_END:
1018
1164
  return *s == 0 ? rre_run(k, s) : NULL;
1019
1165
  case RRE_CHAR:
@@ -1047,15 +1193,25 @@ static const char* rre_match(RreNode* n, const char* s,
1047
1193
  }
1048
1194
  case RRE_REP: {
1049
1195
  /* Two passes: count the greedy maximum, then store the
1050
- * end position of every prefix count in a heap array. */
1196
+ * end position of every prefix count in a heap array.
1197
+ * Each counted iteration is pinned to CONSUME (the
1198
+ * RRE_MINPOS continuation): a nullable body whose first
1199
+ * alternative matches empty must not end the count
1200
+ * while later alternatives progress (reD3-6:
1201
+ * ((boy|(girl))...?)|(man|woman)... under 'woman1y'). */
1051
1202
  size_t cap = n->hi < 0 ? 64 : (size_t)n->hi + 1;
1052
1203
  const char** ends =
1053
1204
  (const char**)malloc((cap + 1) * sizeof(*ends));
1054
1205
  if (!ends) return NULL;
1206
+ RreNode minpos;
1207
+ memset(&minpos, 0, sizeof(minpos));
1208
+ minpos.kind = RRE_MINPOS;
1209
+ RreCont mk = {&minpos, NULL};
1055
1210
  ends[0] = s;
1056
1211
  size_t cnt = 0;
1057
1212
  while (n->hi < 0 || (int)cnt < n->hi) {
1058
- const char* r = rre_match(n->l, ends[cnt], NULL);
1213
+ minpos.l = (RreNode*)ends[cnt];
1214
+ const char* r = rre_match(n->l, ends[cnt], &mk);
1059
1215
  if (!r || r == ends[cnt]) break;
1060
1216
  if (cnt == cap) {
1061
1217
  cap *= 2;
@@ -1082,7 +1238,11 @@ static const char* rre_match(RreNode* n, const char* s,
1082
1238
  }
1083
1239
 
1084
1240
  int rng_regex_supported(const char* pat) {
1085
- if (!pat || !*pat) return 0;
1241
+ if (!pat) return 0;
1242
+ /* an EMPTY branch is a valid regExp (F.1 [1]: branch*) — it
1243
+ * matches only the empty string (reA1/reA7: pattern='' with
1244
+ * value='' [valid]; matches() implements the semantics) */
1245
+ if (!*pat) return 1;
1086
1246
  RreParser ps;
1087
1247
  ps.p = pat;
1088
1248
  ps.depth = 0;
@@ -455,9 +455,15 @@ static XsdSimple* xsd_capture_simple(LeptrisElement st) {
455
455
  if (!fl || (fu && strcmp(fu, XSD_NS) != 0)) continue;
456
456
  const char* val =
457
457
  leptris_element_attribute(fe, "value");
458
- if (strcmp(fl, "pattern") == 0)
459
- simple->pattern = xsd_strdup(val);
460
- else if (strcmp(fl, "enumeration") == 0) {
458
+ if (strcmp(fl, "pattern") == 0) {
459
+ XsdFacetValue* fv =
460
+ (XsdFacetValue*)calloc(1, sizeof(*fv));
461
+ if (fv) {
462
+ fv->text = xsd_strdup(val);
463
+ fv->next = simple->patterns;
464
+ simple->patterns = fv;
465
+ }
466
+ } else if (strcmp(fl, "enumeration") == 0) {
461
467
  XsdFacetValue* fv =
462
468
  (XsdFacetValue*)calloc(1, sizeof(*fv));
463
469
  if (fv) {
@@ -659,9 +665,17 @@ static int xsd_deriv_valid(struct leptris_xsd_schema* s,
659
665
  if (ok && t->length >= 0 && (long)n != t->length) ok = 0;
660
666
  if (ok && t->min_length >= 0 && (long)n < t->min_length) ok = 0;
661
667
  if (ok && t->max_length >= 0 && (long)n > t->max_length) ok = 0;
662
- /* pattern applies to the whole lexical */
663
- if (ok && t->pattern && !rng_regex_matches(t->pattern, v))
664
- ok = 0;
668
+ /* pattern applies to the whole lexical; several patterns are
669
+ * a disjunction (p16: same as [abc]+|[123]+) */
670
+ if (ok && t->patterns) {
671
+ int matched = 0;
672
+ for (XsdFacetValue* p = t->patterns; p; p = p->next)
673
+ if (rng_regex_matches(p->text, v)) {
674
+ matched = 1;
675
+ break;
676
+ }
677
+ if (!matched) ok = 0;
678
+ }
665
679
  return ok;
666
680
  }
667
681
  if (t->deriv == XSD_SIMPLE_UNION) {
@@ -709,6 +723,24 @@ static void xsd_set_error(struct leptris_xsd_schema* s, const char* msg) {
709
723
  }
710
724
  }
711
725
 
726
+ /* XSD Part 2 §4.3.4: every pattern facet value is a regular
727
+ * expression — an unsupported one is a schema error AT COMPILE
728
+ * time (reG26-33/reH19: the suite's schemaTest=invalid rows, e.g.
729
+ * the mid-dash [a-c-1-4x-z-7-9]). Walks the def chains so inline
730
+ * anonymous members are covered too. */
731
+ extern int rng_regex_supported(const char* pat);
732
+ static int xsd_patterns_supported(const XsdSimple* t, int depth) {
733
+ if (!t || depth > 32) return 1;
734
+ for (const XsdFacetValue* p = t->patterns; p; p = p->next)
735
+ if (!rng_regex_supported(p->text)) return 0;
736
+ if (!xsd_patterns_supported(t->base_def, depth + 1)) return 0;
737
+ if (!xsd_patterns_supported(t->item_def, depth + 1)) return 0;
738
+ for (size_t i = 0; i < t->member_def_count; i++)
739
+ if (!xsd_patterns_supported(t->member_defs[i], depth + 1))
740
+ return 0;
741
+ return 1;
742
+ }
743
+
712
744
  /* A top-level schema-language declaration component. */
713
745
  static int xsd_is_declaration(const char* local, const char* uri) {
714
746
  if (uri && strcmp(uri, XSD_NS) != 0) return 0;
@@ -2086,6 +2118,15 @@ static LeptrisXsdSchema xsd_compile_impl(const char* xsd_text,
2086
2118
  xsd_resolve_extension_bases(s);
2087
2119
  xsd_resolve_pending_attr_refs(s);
2088
2120
 
2121
+ for (const XsdSimple* t = s->simple_types; t; t = t->next)
2122
+ if (!xsd_patterns_supported(t, 0)) {
2123
+ xsd_set_error(s, "pattern facet is not a supported "
2124
+ "regular expression");
2125
+ if (status) *status = LEPTRIS_ERROR_PARSE;
2126
+ leptris_document_free(doc);
2127
+ return (LeptrisXsdSchema)s;
2128
+ }
2129
+
2089
2130
  leptris_document_free(doc);
2090
2131
  return s;
2091
2132
 
@@ -2572,7 +2613,13 @@ static void xsd_free_simple_one(XsdSimple* t) {
2572
2613
  free(t->name);
2573
2614
  free(t->ns);
2574
2615
  free(t->base);
2575
- free(t->pattern);
2616
+ XsdFacetValue* pv = t->patterns;
2617
+ while (pv) {
2618
+ XsdFacetValue* pn = pv->next;
2619
+ free(pv->text);
2620
+ free(pv);
2621
+ pv = pn;
2622
+ }
2576
2623
  XsdFacetValue* fv = t->enum_values;
2577
2624
  while (fv) {
2578
2625
  XsdFacetValue* fn = fv->next;