leptris 1.9.402.0 → 1.9.403.1

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: d5f94b3da7e10b2b6d9e8f48651c4ed543d8ea018df365eef5a6f537ee6e27f3
4
- data.tar.gz: 5d26cabfa01b4ef93cfda24e5dcd65d31a87a7e88d8099eecf2da0b25fff80e0
3
+ metadata.gz: e693194897d5163da1aac3e2b46c4ac2c5f95259545142f7becd2d482eab0da1
4
+ data.tar.gz: 70beaf7b58dce1921048dde8b20a9d0413509ce8426d9f2942622461a5f1497d
5
5
  SHA512:
6
- metadata.gz: 40f4dece236fd7c93eb49dc9cf3b75fc39a24c1ace2838dbd84908a9d99bed0510b60475ca26a0b29c964c79c9f44fdb2a3a557fd95bbef58880e0387b528ad0
7
- data.tar.gz: d285d269c17532b3ab641548e310484321809cbf922a6ea474a87c6757346b9bc8986aa7937c97d7987ce3c05a32e8eb0d060d90f09bfcc62468518842cb5444
6
+ metadata.gz: 334d3583a98d67c1eaff192e46635f78cb0817eb6058e2dcb4a8b592bd9d50f8ad1eb87e2cc77dc665068ab7b82fd485814e0b5ca143174a3fff4e26e9f90c01
7
+ data.tar.gz: 159e84e937d7e84e1649b5c0f98350df901a31d29739b4fd19bcc7e4c11d22c2b19e2e0d806f393aafc1c9ae68d5a06ad6a7552e189e2ba2b84ed717ebc6b8c3
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
@@ -273,6 +273,23 @@ task :compile do
273
273
  raise "utf8proc shared library not found after build" unless u8_lib
274
274
  cp(u8_lib, "lib/#{File.basename(u8_lib)}")
275
275
  sign_darwin_binaries("lib/libleptris#{ext}", "lib/#{File.basename(u8_lib)}")
276
+ # ruby#582 dev follow-through: a source checkout carrying the
277
+ # release-assembly vendor copy (lib/leptris/vendor/<platform>/)
278
+ # would shadow the fresh lib/ dylib — ffi_lib prefers vendor_dirs.
279
+ # Sync the platform copy so `rake compile` keeps every vendored
280
+ # location at the built engine version (CI source-install lanes
281
+ # hit the same shadow).
282
+ # the vendor dir spelling comes from the FFI loader's own platform
283
+ # derivation (RUBY_PLATFORM carries the darwin OS version:
284
+ # "arm64-darwin23" -> vendor "arm64-darwin")
285
+ cpu = RUBY_PLATFORM.split('-').first
286
+ os = RUBY_PLATFORM.include?('darwin') ? 'darwin' : 'linux'
287
+ vendor_dir = "lib/leptris/vendor/#{cpu}-#{os}"
288
+ if Dir.exist?(vendor_dir)
289
+ cp(lib, File.join(vendor_dir, "libleptris#{ext}"))
290
+ sign_darwin_binaries(File.join(vendor_dir, "libleptris#{ext}"))
291
+ puts "Synced #{vendor_dir}/libleptris#{ext}"
292
+ end
276
293
  puts "Vendored #{File.basename(lib)} + #{File.basename(u8_lib)} into lib/"
277
294
 
278
295
  # Opt-in native read layer ext (#185): built and vendored beside
@@ -165,4 +165,10 @@ end
165
165
  # same basename — exported by native.c and pinned in the Windows
166
166
  # .def above.
167
167
  minor_us = RUBY_VERSION[/\A\d+\.\d+/].tr(".", "_")
168
+ # ruby#582: hide every internal symbol; only the Init_* entry
169
+ # points opt back in (visibility("default")). Linux's flat symbol
170
+ # scope otherwise lets another gem's exports hijack our calls.
171
+ unless RUBY_PLATFORM =~ /mswin|mingw/
172
+ append_cflags("-fvisibility=hidden")
173
+ end
168
174
  create_makefile("leptris/xml/native_#{minor_us}")
@@ -3701,6 +3701,11 @@ static VALUE leptris_native_resolve_rb(VALUE self, VALUE lib_path)
3701
3701
  */
3702
3702
  #if defined(_WIN32)
3703
3703
  # define LEPTRIS_INIT_EXPORT __declspec(dllexport)
3704
+ #elif defined(__GNUC__) || defined(__clang__)
3705
+ /* -fvisibility=hidden (extconf) keeps every internal symbol off
3706
+ * the dynamic table; the entry points opt back in (#582) so no
3707
+ * internal name can clash with another gem's exports. */
3708
+ # define LEPTRIS_INIT_EXPORT __attribute__((visibility("default")))
3704
3709
  #else
3705
3710
  # define LEPTRIS_INIT_EXPORT
3706
3711
  #endif
@@ -3993,7 +3998,15 @@ static VALUE nf_capabilities(VALUE module) {
3993
3998
  return hash;
3994
3999
  }
3995
4000
 
3996
- LEPTRIS_INIT_EXPORT void Init_native(void)
4001
+ /* leptris-ruby#582: the setup body is PRIVATE (static) so the
4002
+ * per-minor entry points call leptris's own code unconditionally.
4003
+ * MRI loads extensions into the global symbol scope on Linux —
4004
+ * when the per-minor entries called the exported `Init_native`,
4005
+ * a second gem's `Init_native` (loaded first) hijacked the call
4006
+ * and leptris's setup never ran (NativeNode undefined). The
4007
+ * exported plain `Init_native` stays only for the mkmf .def
4008
+ * contract; nothing in the gem loads it. */
4009
+ static void leptris_native_setup(void)
3997
4010
  {
3998
4011
  VALUE m_leptris, m_xml, m_native;
3999
4012
 
@@ -4236,9 +4249,17 @@ LEPTRIS_INIT_EXPORT void Init_native(void)
4236
4249
  * unconditionally on every platform since ruby#476: the darwin/
4237
4250
  * Linux per-minor bundles (native_<minor>) resolve these too —
4238
4251
  * an artifact only ever loads under the Ruby minor it was built
4239
- * against. */
4240
- LEPTRIS_INIT_EXPORT void Init_native_3_1(void) { Init_native(); }
4241
- LEPTRIS_INIT_EXPORT void Init_native_3_2(void) { Init_native(); }
4242
- LEPTRIS_INIT_EXPORT void Init_native_3_3(void) { Init_native(); }
4243
- LEPTRIS_INIT_EXPORT void Init_native_3_4(void) { Init_native(); }
4244
- LEPTRIS_INIT_EXPORT void Init_native_4_0(void) { Init_native(); }
4252
+ * against. Each entry calls the PRIVATE setup directly (#582):
4253
+ * routing through the exported `Init_native` let whichever gem
4254
+ * defined that symbol first win the call on Linux's flat
4255
+ * namespace. */
4256
+ LEPTRIS_INIT_EXPORT void Init_native_3_1(void) { leptris_native_setup(); }
4257
+ LEPTRIS_INIT_EXPORT void Init_native_3_2(void) { leptris_native_setup(); }
4258
+ LEPTRIS_INIT_EXPORT void Init_native_3_3(void) { leptris_native_setup(); }
4259
+ LEPTRIS_INIT_EXPORT void Init_native_3_4(void) { leptris_native_setup(); }
4260
+ LEPTRIS_INIT_EXPORT void Init_native_4_0(void) { leptris_native_setup(); }
4261
+
4262
+ /* The plain entry stays exported for the mkmf .def contract (see
4263
+ * the LEPTRIS_INIT_EXPORT note); the gem's own loader only ever
4264
+ * requires the per-minor bundles. */
4265
+ LEPTRIS_INIT_EXPORT void Init_native(void) { leptris_native_setup(); }
@@ -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.1"
5
5
  end
@@ -209,7 +209,12 @@ class Leptris::XML::Descriptor
209
209
  # libleptris 1.9.312 (#1551): the root plan's serialization
210
210
  # prefix (ns_form EXACT rows emit "prefix:local" and the
211
211
  # xmlns declaration lands once on the output root).
212
- ep[:ns_prefix] = anchor_string(anchors, plan[:ns_prefix]) if plan[:ns_prefix]
212
+ # leptris#1941: the compiler's tree ns Hash carries the wire
213
+ # prefix ({exact:, prefix:}) — the emission prefix rides the
214
+ # same slot as an explicit plan[:ns_prefix].
215
+ prefix_src = plan[:ns_prefix] ||
216
+ (plan[:ns].is_a?(Hash) ? plan[:ns][:prefix] : nil)
217
+ ep[:ns_prefix] = anchor_string(anchors, prefix_src) if prefix_src
213
218
  attrs = plan[:attributes] || []
214
219
  attr_memory = attrs.empty? ? nil :
215
220
  ::FFI::MemoryPointer.new(Leptris::XML::FFI::AttrPlan, attrs.size)
@@ -233,7 +238,9 @@ class Leptris::XML::Descriptor
233
238
  anchor_string(anchors, row[:ns].fetch(:exact)) : nil
234
239
  # libleptris 1.9.312 (#1551): serialization prefix — with
235
240
  # ns_form EXACT the attribute emits as "prefix:local".
236
- ap[:ns_prefix] = anchor_string(anchors, row[:ns_prefix]) if row[:ns_prefix]
241
+ aprefix = row[:ns_prefix] ||
242
+ (row[:ns].is_a?(Hash) ? row[:ns][:prefix] : nil)
243
+ ap[:ns_prefix] = anchor_string(anchors, aprefix) if aprefix
237
244
  pack_predicates(ap, row, anchors)
238
245
  end
239
246
  ep[:attribute_count] = attrs.size
@@ -271,7 +278,9 @@ class Leptris::XML::Descriptor
271
278
  # libleptris 1.9.312 (#1551): serialization prefix — with
272
279
  # ns_form EXACT the element emits as "prefix:local" and
273
280
  # its declaration lands once on the output root.
274
- cp[:ns_prefix] = anchor_string(anchors, row[:ns_prefix]) if row[:ns_prefix]
281
+ cprefix = row[:ns_prefix] ||
282
+ (row[:ns].is_a?(Hash) ? row[:ns][:prefix] : nil)
283
+ cp[:ns_prefix] = anchor_string(anchors, cprefix) if cprefix
275
284
  pack_predicates(cp, row, anchors)
276
285
  end
277
286
  ep[:child_count] = children.size
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;