leptris 1.9.355.0-arm-linux → 1.9.359.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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/README.adoc +13 -5
  4. data/Rakefile +1 -1
  5. data/ext/leptris/native/native.c +383 -5
  6. data/lib/leptris/version.rb +1 -1
  7. data/lib/leptris/xml/cdata.rb +3 -0
  8. data/lib/leptris/xml/comment.rb +3 -0
  9. data/lib/leptris/xml/declaration.rb +59 -0
  10. data/lib/leptris/xml/doc_type.rb +33 -1
  11. data/lib/leptris/xml/document.rb +74 -2
  12. data/lib/leptris/xml/element.rb +21 -1
  13. data/lib/leptris/xml/entity_reference.rb +3 -0
  14. data/lib/leptris/xml/native.so +0 -0
  15. data/lib/leptris/xml/node_set.rb +22 -0
  16. data/lib/leptris/xml/processing_instruction.rb +3 -0
  17. data/lib/leptris/xml/sax/parser.rb +102 -78
  18. data/lib/leptris/xml/text.rb +4 -0
  19. data/lib/leptris/xml.rb +14 -0
  20. data/lib/libleptris.so +0 -0
  21. data/scripts/gem_smoke.rb +6 -3
  22. data/vendor-src/README.md +1 -1
  23. data/vendor-src/libleptris/CHANGELOG.md +134 -0
  24. data/vendor-src/libleptris/CMakeLists.txt +1 -1
  25. data/vendor-src/libleptris/TODO.xslt-full/REMAINING.md +37 -18
  26. data/vendor-src/libleptris/cli/commands/validate.c +15 -2
  27. data/vendor-src/libleptris/src/include/leptris.h +60 -4
  28. data/vendor-src/libleptris/src/leptris/dom/element.c +8 -0
  29. data/vendor-src/libleptris/src/leptris/dtd/content_check.c +280 -144
  30. data/vendor-src/libleptris/src/leptris/dtd/parser.c +17 -4
  31. data/vendor-src/libleptris/src/leptris/rng/parse.c +53 -8
  32. data/vendor-src/libleptris/src/leptris/rng/validate.c +63 -21
  33. data/vendor-src/libleptris/src/leptris/xinclude/xinclude.c +304 -12
  34. data/vendor-src/libleptris/src/leptris/xpath/evaluator.c +30 -0
  35. data/vendor-src/libleptris/src/leptris/xpath/evaluator.h +11 -0
  36. data/vendor-src/libleptris/src/leptris/xpath/evaluator_axes.c +3 -3
  37. data/vendor-src/libleptris/src/leptris/xpath/evaluator_path.c +4 -20
  38. data/vendor-src/libleptris/src/leptris/xpath/parser.c +4 -1
  39. data/vendor-src/libleptris/src/leptris/xpath/vm.c +41 -11
  40. data/vendor-src/libleptris/src/leptris/xpath/xpath_compiled.c +4 -3
  41. data/vendor-src/libleptris/src/leptris/xpath/xpath_public.c +2 -1
  42. data/vendor-src/libleptris/src/leptris/xsd/compile.c +981 -38
  43. data/vendor-src/libleptris/src/leptris/xsd/content_model.c +15 -3
  44. data/vendor-src/libleptris/src/leptris/xsd/validate.c +27 -9
  45. data/vendor-src/libleptris/src/leptris/xsd/xsd_internal.h +1 -0
  46. data/vendor-src/libleptris/test/cli/test_cli.cpp +50 -14
  47. data/vendor-src/libleptris/test/dom/test_dom.cpp +27 -0
  48. data/vendor-src/libleptris/test/dtd/test_dtd_validate.cpp +80 -4
  49. data/vendor-src/libleptris/test/rng/include-cases/attr-text-choice.rng +18 -0
  50. data/vendor-src/libleptris/test/rng/include-cases/dup-inc-mid.rng +7 -0
  51. data/vendor-src/libleptris/test/rng/include-cases/dup-inc-shared.rng +5 -0
  52. data/vendor-src/libleptris/test/rng/include-cases/dup-inc-top.rng +6 -0
  53. data/vendor-src/libleptris/test/rng/test_rng.cpp +101 -0
  54. data/vendor-src/libleptris/test/xinclude/test_xinclude.cpp +261 -0
  55. data/vendor-src/libleptris/test/xpath/test_xpath.cpp +169 -0
  56. data/vendor-src/libleptris/test/xpath/test_xpath_conformance.cpp +8 -1
  57. data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +128 -11
  58. data/vendor-src/libleptris/vcpkg.json +1 -1
  59. metadata +7 -2
@@ -241,6 +241,12 @@ static int attr_leaves_satisfied(RngVal* v, RngPattern* head,
241
241
  *has_leaf = 1;
242
242
  if (token_matches_leaf(value, c)) return 1;
243
243
  continue;
244
+ case RNG_TEXT:
245
+ /* <text/> in an attribute's content matches ANY
246
+ * value (bDateAttributes: enum OR open text —
247
+ * leptris#1709's bipm half). */
248
+ *has_leaf = 1;
249
+ return 1;
244
250
  case RNG_REF: {
245
251
  RngDefine* d = find_define(v->g, c->name);
246
252
  if (d && d->body &&
@@ -435,30 +441,55 @@ static size_t match_seq(RngVal* v, RngPattern* p, LeptrisNodeRef* kids,
435
441
  return i;
436
442
  }
437
443
  case RNG_INTERLEAVE: {
438
- /* Any order; each child pattern is used exactly once and
439
- * all of them must match. */
440
- size_t count = 0;
441
- for (RngPattern* c = p->first_child; c; c = c->next) count++;
442
- int used[32] = {0};
443
- for (size_t k = 0; k < count; k++) {
444
- int matched_any = 0;
445
- size_t ci = 0;
446
- for (RngPattern* c = p->first_child; c;
447
- c = c->next, ci++) {
448
- if (ci < 32 && used[ci]) continue;
449
- size_t r = match_seq(v, c, kids, n, idx);
450
- if (r != (size_t)-1) {
451
- matched_any = 1;
452
- idx = r;
453
- if (ci < 32) used[ci] = 1;
454
- break;
444
+ /* Any order; every branch must be satisfied. A single
445
+ * assignment pass is unsound against interleaved
446
+ * zeroOrMore branches: a branch whose turn precedes the
447
+ * elements it matches zero-widths, gets marked used, and
448
+ * strands them (leptris#1709: relaton-ieee's 2nd/3rd
449
+ * <ics>). Consume to a fixpoint — branches take turns
450
+ * while ANY of them advances — then the remainder must
451
+ * be zero-width satisfiable. */
452
+ RngPattern* ch[64];
453
+ size_t cn = 0;
454
+ for (RngPattern* c = p->first_child; c && cn < 64;
455
+ c = c->next)
456
+ ch[cn++] = c;
457
+ int used[64] = {0};
458
+ int progressed = 1;
459
+ size_t i = idx;
460
+ while (progressed) {
461
+ progressed = 0;
462
+ for (size_t b = 0; b < cn; b++) {
463
+ if (used[b]) continue;
464
+ size_t r = match_seq(v, ch[b], kids, n, i);
465
+ if (r != (size_t)-1 && r > i) {
466
+ used[b] = 1;
467
+ i = r;
468
+ progressed = 1;
469
+ } else if (r != (size_t)-1) {
470
+ /* zero-width here: leave the branch unused so
471
+ * a later position can still feed it. */
472
+ v->failed = 0;
473
+ v->err[0] = 0;
474
+ } else {
475
+ v->failed = 0;
476
+ v->err[0] = 0;
455
477
  }
456
- v->failed = 0;
457
- v->err[0] = 0;
458
478
  }
459
- if (!matched_any) return (size_t)-1;
460
479
  }
461
- return idx;
480
+ for (size_t b = 0; b < cn; b++) {
481
+ if (used[b]) continue;
482
+ size_t r = match_seq(v, ch[b], kids, n, i);
483
+ if (r == (size_t)-1 || r != i) {
484
+ /* A branch that consumes here contradicts the
485
+ * fixpoint above — treat as unsatisfied. */
486
+ return (size_t)-1;
487
+ }
488
+ v->failed = 0;
489
+ v->err[0] = 0;
490
+ used[b] = 1;
491
+ }
492
+ return i;
462
493
  }
463
494
  case RNG_OPTIONAL: {
464
495
  size_t r = match_seq(v, p->first_child, kids, n, idx);
@@ -1719,6 +1750,17 @@ static void diagnose_element(RngVal* v, RngPattern* p, LeptrisElement e) {
1719
1750
  "element \"%s\" not allowed anywhere; expected %s",
1720
1751
  x, expected);
1721
1752
  }
1753
+ /* leptris#1704 (Jing parity): the skipped element still
1754
+ * gets its attributes validated — against its OWN
1755
+ * definition — or schema-attribute constraints (align
1756
+ * enums) go invisible exactly where documents are most
1757
+ * broken. Jing reports both, position first. */
1758
+ {
1759
+ RngDefine* own = find_define(v->g, x);
1760
+ if (own && own->body)
1761
+ diagnose_attrs(v, dpat_new(v, RNG_ELEMENT, own->body),
1762
+ kid);
1763
+ }
1722
1764
  /* Skip the offending child; position unchanged. */
1723
1765
  }
1724
1766
  if (!nullable_state(v, state)) {
@@ -514,10 +514,14 @@ static LeptrisElement xptr_select(LeptrisDocument doc, const char* value) {
514
514
  return found;
515
515
  }
516
516
 
517
- /* Forward decl for internal recursion-aware variant. */
517
+ /* Forward decls: internal recursion variant + catalog lookup. */
518
518
  static LeptrisStatus xinclude_process_internal(struct leptris_document* doc,
519
519
  const char* base_url,
520
- int depth);
520
+ int depth,
521
+ const leptris_xinclude_opts* opts);
522
+ static void xinclude_catalog_lookup(const char* catalog_path,
523
+ const char* uri, char* out,
524
+ size_t out_size);
521
525
 
522
526
  /* TODO 117 Phase C: cycle detection.
523
527
  *
@@ -562,19 +566,163 @@ static CycleNode* cycle_pop(CycleNode* ancestors) {
562
566
  * (parse error, alloc failure), 1 otherwise. The `depth` parameter
563
567
  * (TODO 92 Phase 5) tracks how many xi:include layers we've descended
564
568
  * through; XINCLUDE_MAX_DEPTH stops mutual-recursion attacks. */
569
+ /* ---- TODO.assemble 03: xml:base (RFC 3986) ------------------------------
570
+ *
571
+ * The effective base of an element = merge(inherited_base, this
572
+ * element's xml:base). merge_uri implements RFC 3986 §5.2 for the
573
+ * cases hrefs actually exercise: absolute refs replace; scheme-
574
+ * relative ("//host/x") keeps the scheme; root-relative ("/x")
575
+ * keeps scheme+authority; otherwise the reference rides the base's
576
+ * path directory with dot-segments removed. */
577
+ static int uri_is_absolute(const char* s) {
578
+ for (const char* p = s; *p; p++) {
579
+ if (*p == ':') return p != s;
580
+ if (*p == '/' || *p == '?' || *p == '#') return 0;
581
+ }
582
+ return 0;
583
+ }
584
+
585
+ static void copy_dir_of(char* out, size_t out_size, const char* uri) {
586
+ const char* slash = strrchr(uri, '/');
587
+ if (!slash) {
588
+ out[0] = 0;
589
+ return;
590
+ }
591
+ size_t bl = (size_t)(slash - uri);
592
+ if (bl >= out_size) bl = out_size - 1;
593
+ memcpy(out, uri, bl);
594
+ out[bl] = 0;
595
+ }
596
+
597
+ static void remove_dot_segments(char* path) {
598
+ /* Rebuild the path segment by segment, dropping "." segments and
599
+ * popping ".." against the last emitted one (RFC 3986 §5.2.4 for
600
+ * the path-only form — no query/fragment here). */
601
+ char tmp[8192];
602
+ size_t tl = strlen(path);
603
+ if (tl >= sizeof(tmp)) return; /* oversized: leave as-is */
604
+ memcpy(tmp, path, tl + 1);
605
+
606
+ char* out = path;
607
+ size_t out_len = 0;
608
+ const char* r = tmp;
609
+ int absolute = (*r == '/');
610
+ if (absolute) r++;
611
+
612
+ while (*r) {
613
+ const char* seg = r;
614
+ while (*r && *r != '/') r++;
615
+ size_t sl = (size_t)(r - seg);
616
+ int had_slash = (*r == '/');
617
+ if (had_slash) r++;
618
+
619
+ if (sl == 1 && seg[0] == '.') continue;
620
+ if (sl == 2 && seg[0] == '.' && seg[1] == '.') {
621
+ if (out_len > 0) {
622
+ while (out_len > 0 && out[out_len - 1] != '/') out_len--;
623
+ if (out_len > 0) out_len--; /* the separator itself */
624
+ }
625
+ out[out_len] = 0;
626
+ continue;
627
+ }
628
+ if (out_len == 0) {
629
+ if (absolute) out[out_len++] = '/';
630
+ } else if (out[out_len - 1] != '/') {
631
+ out[out_len++] = '/';
632
+ }
633
+ memcpy(out + out_len, seg, sl);
634
+ out_len += sl;
635
+ out[out_len] = 0;
636
+ }
637
+ if (tl > 0 && tmp[tl - 1] == '/' &&
638
+ !(out_len > 0 && out[out_len - 1] == '/')) {
639
+ if (out_len == 0) {
640
+ if (absolute) out[out_len++] = '/';
641
+ } else if (out[out_len - 1] != '/') {
642
+ out[out_len++] = '/';
643
+ }
644
+ out[out_len] = 0;
645
+ }
646
+ }
647
+
648
+ static int merge_uri(const char* base, const char* ref, char* out,
649
+ size_t out_size) {
650
+ if (!ref || !ref[0]) {
651
+ snprintf(out, out_size, "%s", base ? base : "");
652
+ return 0;
653
+ }
654
+ if (!base || !base[0] || uri_is_absolute(ref)) {
655
+ snprintf(out, out_size, "%s", ref);
656
+ return 0;
657
+ }
658
+ /* Filesystem-absolute reference: used as-is (the processor's
659
+ * base is a plain directory prefix, not a URI with authority). */
660
+ if (ref[0] == '/') {
661
+ snprintf(out, out_size, "%s", ref);
662
+ return 0;
663
+ }
664
+ if (strncmp(ref, "//", 2) == 0) {
665
+ /* scheme-relative: reuse the base's scheme */
666
+ const char* colon = strchr(base, ':');
667
+ if (colon) {
668
+ int n = snprintf(out, out_size, "%.*s:%s",
669
+ (int)(colon - base), base, ref);
670
+ return (n < 0 || (size_t)n >= out_size);
671
+ }
672
+ snprintf(out, out_size, "%s", ref);
673
+ return 0;
674
+ }
675
+ /* strip query/fragment from the base for the directory merge */
676
+ char base_path[4096];
677
+ snprintf(base_path, sizeof(base_path), "%s", base);
678
+ char* cut = strpbrk(base_path, "?#");
679
+ if (cut) *cut = 0;
680
+ char dir[4096];
681
+ copy_dir_of(dir, sizeof(dir), base_path);
682
+ char joined[8192];
683
+ if (dir[0])
684
+ snprintf(joined, sizeof(joined), "%s/%s", dir, ref);
685
+ else
686
+ snprintf(joined, sizeof(joined), "%s", ref);
687
+ remove_dot_segments(joined);
688
+ snprintf(out, out_size, "%s", joined);
689
+ return 0;
690
+ }
691
+
692
+ /* The element's effective base: nearest xml:base (this element or
693
+ * nearest ancestor carrying one), merged over the inherited base. */
694
+ static void effective_xml_base(LeptrisElement elem, const char* inherited,
695
+ char* out, size_t out_size) {
696
+ const char* xb = get_attr_value(elem, "xml:base");
697
+ if (xb && xb[0] && inherited && inherited[0] &&
698
+ !uri_is_absolute(xb)) {
699
+ merge_uri(inherited, xb, out, out_size);
700
+ } else if (xb && xb[0]) {
701
+ snprintf(out, out_size, "%s", xb);
702
+ } else {
703
+ snprintf(out, out_size, "%s", inherited ? inherited : "");
704
+ }
705
+ }
706
+
565
707
  static int process_element_xinclude(LeptrisElement elem,
566
708
  struct leptris_document* doc,
567
709
  const char* base_url,
710
+ const leptris_xinclude_opts* opts,
568
711
  int depth,
569
712
  CycleNode* ancestors) {
570
713
  if (!elem) return 1;
571
714
 
715
+ char subtree_base[4096];
716
+ effective_xml_base(elem, base_url, subtree_base, sizeof(subtree_base));
717
+ base_url = subtree_base;
718
+
572
719
  LeptrisNodeRef child = leptris_node_first_child((LeptrisNodeRef)elem);
573
720
  while (child) {
574
721
  LeptrisNodeRef next = leptris_node_next_sibling(child);
575
722
  if (leptris_node_get_type(child) == LEPTRIS_NODE_TYPE_ELEMENT) {
576
723
  int rc = process_element_xinclude((LeptrisElement)child, doc,
577
- base_url, depth, ancestors);
724
+ base_url, opts, depth,
725
+ ancestors);
578
726
  if (!rc) return 0;
579
727
  }
580
728
  child = next;
@@ -608,8 +756,35 @@ static int process_element_xinclude(LeptrisElement elem,
608
756
  if (!is_xml && (frag || (xptr_attr && xptr_attr[0]))) resource_error = 1;
609
757
 
610
758
  char full_path[4096];
611
- if (!resource_error &&
612
- !join_path(full_path, sizeof(full_path), base_url, href_base)) return 1;
759
+ if (!resource_error) {
760
+ int rv;
761
+ if (base_url && base_url[0])
762
+ rv = merge_uri(base_url, href_base, full_path, sizeof(full_path));
763
+ else
764
+ rv = merge_uri(NULL, href_base, full_path, sizeof(full_path));
765
+ if (rv) return 1;
766
+ }
767
+ /* XML Catalog lookup (exact <uri name=...> mappings) rewrites
768
+ * the URI before the policy gate — catalogs exist precisely to
769
+ * map remote names onto local resources. */
770
+ char catalog_hit[4096];
771
+ catalog_hit[0] = 0;
772
+ if (!resource_error && opts && opts->catalog_path && opts->catalog_path[0]) {
773
+ xinclude_catalog_lookup(opts->catalog_path, full_path, catalog_hit,
774
+ sizeof(catalog_hit));
775
+ }
776
+ const char* fetch_uri =
777
+ catalog_hit[0] ? catalog_hit : full_path;
778
+ /* TODO.assemble 04: network policy — remote schemes are resource
779
+ * errors unless the caller explicitly enables them; the gate runs
780
+ * on the POST-catalog URI (a catalog mapping may localize it). */
781
+ int no_network = opts ? opts->no_network : 1;
782
+ if (!resource_error && no_network && uri_is_absolute(fetch_uri) &&
783
+ (strncmp(fetch_uri, "http://", 7) == 0 ||
784
+ strncmp(fetch_uri, "https://", 8) == 0 ||
785
+ strncmp(fetch_uri, "ftp://", 6) == 0 ||
786
+ strncmp(fetch_uri, "ftps://", 7) == 0))
787
+ resource_error = 1;
613
788
 
614
789
  /* TODO 117 Phase C: cycle detection. If `full_path` is already in
615
790
  * the ancestor chain, we'd be re-including something we're
@@ -619,9 +794,21 @@ static int process_element_xinclude(LeptrisElement elem,
619
794
  }
620
795
 
621
796
  size_t content_len = 0;
622
- char* content = resource_error
623
- ? NULL
624
- : load_file_content(full_path, &content_len);
797
+ char* content = NULL;
798
+ int resolver_handled = 0;
799
+ if (!resource_error && opts && opts->resolver) {
800
+ int rr = opts->resolver(fetch_uri, opts->resolver_user, &content,
801
+ &content_len);
802
+ if (rr == 1) {
803
+ resolver_handled = 1;
804
+ } else if (rr < 0) {
805
+ content = NULL; /* forced resource error -> fallback */
806
+ } else {
807
+ content = NULL;
808
+ }
809
+ }
810
+ if (!resource_error && !resolver_handled && !content)
811
+ content = load_file_content(fetch_uri, &content_len);
625
812
 
626
813
  /* The substitute node — element for parse="xml", text for parse="text",
627
814
  * NULL on failure (fallback path below). */
@@ -641,7 +828,21 @@ static int process_element_xinclude(LeptrisElement elem,
641
828
  /* Resolve any xi:include nested inside the included doc
642
829
  * before splicing — XInclude processes recursively.
643
830
  * Bump depth so mutual-recursion stops at MAX_DEPTH. */
644
- xinclude_process_internal(included_doc, base_url, depth + 1);
831
+ /* TODO.assemble 03: nested hrefs inside the included
832
+ * document resolve against the INCLUDED document's
833
+ * own location, not the includer's base. */
834
+ {
835
+ char inc_dir[4096];
836
+ copy_dir_of(inc_dir, sizeof(inc_dir), full_path);
837
+ size_t dl = strlen(inc_dir);
838
+ if (dl + 1 < sizeof(inc_dir) && (dl == 0 ||
839
+ inc_dir[dl-1] != '/')) {
840
+ inc_dir[dl++] = '/';
841
+ inc_dir[dl] = 0;
842
+ }
843
+ xinclude_process_internal(included_doc, inc_dir,
844
+ depth + 1, opts);
845
+ }
645
846
  LeptrisElement inc_root = leptris_document_root(included_doc);
646
847
  if (inc_root) {
647
848
  /* Phase 4 of TODO 92: xpointer attribute selects
@@ -775,11 +976,84 @@ fallback:
775
976
  return 1;
776
977
  }
777
978
 
979
+ /* ---- TODO.assemble 04: XML Catalog (minimal) ----------------------------
980
+ *
981
+ * Parses an XML Catalog file and answers EXACT <uri name="..." uri=
982
+ * "..."/> mappings. The file is re-read per lookup (catalogs are
983
+ * small, XInclude counts are depth-bounded); a missing or malformed
984
+ * catalog simply yields no rewrite. */
985
+ static void xinclude_catalog_lookup(const char* catalog_path,
986
+ const char* uri, char* out,
987
+ size_t out_size) {
988
+ out[0] = 0;
989
+ size_t clen = 0;
990
+ char* text = load_file_content(catalog_path, &clen);
991
+ if (!text) return;
992
+ /* Exact <uri name="..." uri="..."/> mappings; attribute order is
993
+ * free. Malformed input simply yields no rewrite. */
994
+ const char* p = text;
995
+ while ((p = strchr(p, '<')) != NULL) {
996
+ p++;
997
+ while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r')
998
+ p++;
999
+ if (strncmp(p, "uri", 3) != 0 ||
1000
+ (p[3] != ' ' && p[3] != '\t' && p[3] != '\n' && p[3] != '\r' &&
1001
+ p[3] != '/' && p[3] != '>')) {
1002
+ continue;
1003
+ }
1004
+ const char* tag_end = strchr(p, '>');
1005
+ if (!tag_end) break;
1006
+ const char* name_v = NULL;
1007
+ const char* uri_v = NULL;
1008
+ const char* uri_v_end = NULL;
1009
+ const char* q = p + 3;
1010
+ while (q < tag_end) {
1011
+ const char* eq = strchr(q, '=');
1012
+ if (!eq || eq >= tag_end) break;
1013
+ const char* key = eq;
1014
+ while (key > p && key[-1] != ' ' && key[-1] != '\t' &&
1015
+ key[-1] != '\n' && key[-1] != '\r')
1016
+ key--;
1017
+ size_t kl = (size_t)(eq - key);
1018
+ const char* vq = eq + 1;
1019
+ while (vq < tag_end && (*vq == ' ' || *vq == '\t'))
1020
+ vq++;
1021
+ if (vq >= tag_end || (*vq != '"' && *vq != '\'')) {
1022
+ q = eq + 1;
1023
+ continue;
1024
+ }
1025
+ char quote = *vq++;
1026
+ const char* vend = memchr(vq, quote, (size_t)(tag_end - vq));
1027
+ if (!vend) break;
1028
+ if ((kl == 4 && strncmp(key, "name", 4) == 0) &&
1029
+ (size_t)(vend - vq) == strlen(uri) &&
1030
+ strncmp(vq, uri, vend - vq) == 0)
1031
+ name_v = vq;
1032
+ if (kl == 3 && strncmp(key, "uri", 3) == 0) {
1033
+ uri_v = vq;
1034
+ uri_v_end = vend;
1035
+ }
1036
+ if (name_v && uri_v) {
1037
+ size_t urlen = (size_t)(uri_v_end - uri_v);
1038
+ if (urlen >= out_size) urlen = out_size - 1;
1039
+ memcpy(out, uri_v, urlen);
1040
+ out[urlen] = 0;
1041
+ free(text);
1042
+ return;
1043
+ }
1044
+ q = vend + 1;
1045
+ }
1046
+ p = tag_end + 1;
1047
+ }
1048
+ free(text);
1049
+ }
1050
+
778
1051
  /* Internal recursion-aware variant. Aborts with LEPTRIS_ERROR_INVALID_ARG
779
1052
  * if depth exceeds XINCLUDE_MAX_DEPTH (TODO 92 Phase 5). */
780
1053
  static LeptrisStatus xinclude_process_internal(struct leptris_document* doc,
781
1054
  const char* base_url,
782
- int depth) {
1055
+ int depth,
1056
+ const leptris_xinclude_opts* opts) {
783
1057
  if (!doc) return LEPTRIS_ERROR_NULL_ARG;
784
1058
  if (depth > XINCLUDE_MAX_DEPTH) return LEPTRIS_ERROR_INVALID_ARG;
785
1059
 
@@ -789,11 +1063,29 @@ static LeptrisStatus xinclude_process_internal(struct leptris_document* doc,
789
1063
  /* TODO 117 Phase C: thread empty ancestor list into the walk.
790
1064
  * The first include pushes its own URI, so the second visit to the
791
1065
  * same URI is detected as a cycle. */
792
- int rc = process_element_xinclude(root, doc, base_url, depth, NULL);
1066
+ int rc = process_element_xinclude(root, doc, base_url, opts, depth,
1067
+ NULL);
793
1068
  if (!rc) return LEPTRIS_ERROR_IO;
794
1069
  return LEPTRIS_OK;
795
1070
  }
796
1071
 
797
1072
  LEPTRIS_API LeptrisStatus leptris_xinclude_process(LeptrisDocument doc, const char* base_url) {
798
- return xinclude_process_internal(doc, base_url, 0);
1073
+ /* no_network defaults to 1 for the legacy entry too — the remote
1074
+ * refusal is the documented posture (TODO.assemble 04). */
1075
+ leptris_xinclude_opts defaults;
1076
+ memset(&defaults, 0, sizeof(defaults));
1077
+ defaults.no_network = 1;
1078
+ return xinclude_process_internal(doc, base_url, 0, &defaults);
1079
+ }
1080
+
1081
+ LEPTRIS_API LeptrisStatus leptris_xinclude_process_opts(
1082
+ LeptrisDocument doc, const char* base_url,
1083
+ const leptris_xinclude_opts* opts) {
1084
+ leptris_xinclude_opts defaults;
1085
+ if (!opts) {
1086
+ memset(&defaults, 0, sizeof(defaults));
1087
+ defaults.no_network = 1;
1088
+ opts = &defaults;
1089
+ }
1090
+ return xinclude_process_internal(doc, base_url, 0, opts);
799
1091
  }
@@ -10,6 +10,7 @@
10
10
  #include "functions.h"
11
11
  #include "xpath_variables.h"
12
12
  #include "../dom/element.h" /* For LeptrisElement structure */
13
+ #include "../dom/document_node.h"
13
14
  #include "../common/port.h" /* LEPTRIS_THREAD_LOCAL */
14
15
  #include "lexer.h"
15
16
  #include "parser.h"
@@ -99,6 +100,35 @@ XPathContext* xpath_context_new(struct leptris_document* document,
99
100
  * that hold the context for the duration of one eval (the common
100
101
  * case — both leptris_xpath_eval and leptris_xpath_eval_with_vars)
101
102
  * skip the malloc/free pair. */
103
+ const char* xpath_expr_prefix_uri(XPathContext* ctx,
104
+ const char* prefix,
105
+ size_t prefix_len) {
106
+ if (!prefix || prefix_len == 0) return NULL;
107
+ const char* bound = ctx
108
+ ? leptris_xpath_ns_lookup(
109
+ (const struct leptris_xpath_ns_map*)ctx->ns_set,
110
+ prefix, prefix_len)
111
+ : NULL;
112
+ if (bound) return bound;
113
+ if (prefix_len != 5 || memcmp(prefix, "xmlns", 5) != 0)
114
+ return NULL;
115
+ /* In-scope default namespace: the innermost declaration with no
116
+ * prefix, walking ancestor-or-self from the context element. */
117
+ LeptrisElement cur = ctx ? ctx->context_node : NULL;
118
+ if (cur && ((LeptrisNode*)cur)->type == LEPTRIS_NODE_TYPE_DOCUMENT) {
119
+ struct leptris_document* dd = ((LeptrisDocumentNode*)cur)->doc;
120
+ cur = (LeptrisElement)dd->new_dom_root;
121
+ if (!cur) cur = dd->root;
122
+ }
123
+ for (; cur; cur = leptris_element_get_parent(cur)) {
124
+ for (struct leptris_namespace* decl = leptris_elem_namespaces(cur);
125
+ decl; decl = decl->next)
126
+ if (!decl->prefix && decl->uri && decl->uri[0])
127
+ return decl->uri;
128
+ }
129
+ return NULL;
130
+ }
131
+
102
132
  void xpath_context_init(XPathContext* context,
103
133
  struct leptris_document* document,
104
134
  LeptrisElement context_node) {
@@ -48,6 +48,17 @@ typedef struct leptris_xsd_schema* LeptrisXsdSchema;
48
48
  XPathContext* xpath_context_new(struct leptris_document* document,
49
49
  LeptrisElement context_node);
50
50
 
51
+ /* Resolve an EXPRESSION name-test prefix to a namespace URI:
52
+ * explicit bindings first; then the libxml2/nokogiri quirk — the
53
+ * reserved xmlns: prefix resolves to the in-scope DEFAULT
54
+ * namespace of the evaluation context (leptris-ruby#469). Safe to
55
+ * hijack: no valid document carries an element literally prefixed
56
+ * xmlns:, so a conformant query can never need it for anything
57
+ * else. NULL when the prefix is unbound and not xmlns:. */
58
+ const char* xpath_expr_prefix_uri(XPathContext* ctx,
59
+ const char* prefix,
60
+ size_t prefix_len);
61
+
51
62
  /**
52
63
  * Free XPath context
53
64
  *
@@ -506,9 +506,9 @@ static XPathNodeSet* axis_attribute(XPathContext* ctx, LeptrisElement node,
506
506
  * may use a different prefix for the same namespace
507
507
  * (libxslt bug-97). Unbound prefix: fall through to
508
508
  * the literal compare (legacy behavior). */
509
- const char* uri = leptris_xpath_ns_lookup(
510
- (const struct leptris_xpath_ns_map*)ctx->ns_set,
511
- tv, (size_t)(tcolon - tv));
509
+ const char* uri =
510
+ xpath_expr_prefix_uri(ctx, tv,
511
+ (size_t)(tcolon - tv));
512
512
  if (uri && !leptris_sv_is_empty(&attr->name_view)) {
513
513
  const char* a = attr->name_view.data;
514
514
  size_t al = attr->name_view.length;
@@ -176,11 +176,7 @@ int matches_node_test(XPathContext* ctx, LeptrisNode* node, XPathASTNode* test)
176
176
  * that namespace via a different prefix or the default
177
177
  * namespace. Unbound prefix falls through to the
178
178
  * historic literal-prefix comparison. */
179
- const char* test_uri = ctx
180
- ? leptris_xpath_ns_lookup(
181
- (const struct leptris_xpath_ns_map*)ctx->ns_set,
182
- test_prefix, prefix_len)
183
- : NULL;
179
+ const char* test_uri = xpath_expr_prefix_uri(ctx, test_prefix, prefix_len);
184
180
  if (test_uri) {
185
181
  const char* node_uri = leptris_element_get_namespace_uri(elem);
186
182
  return node_uri && strcmp(node_uri, test_uri) == 0 &&
@@ -207,11 +203,7 @@ int matches_node_test(XPathContext* ctx, LeptrisNode* node, XPathASTNode* test)
207
203
  * previously ignored: //t:* matched EVERY element. */
208
204
  if (test->prefix) {
209
205
  size_t prefix_len = strlen(test->prefix);
210
- const char* test_uri = ctx
211
- ? leptris_xpath_ns_lookup(
212
- (const struct leptris_xpath_ns_map*)ctx->ns_set,
213
- test->prefix, prefix_len)
214
- : NULL;
206
+ const char* test_uri = xpath_expr_prefix_uri(ctx, test->prefix, prefix_len);
215
207
  if (test_uri) {
216
208
  const char* node_uri =
217
209
  leptris_element_get_namespace_uri(elem);
@@ -231,11 +223,7 @@ int matches_node_test(XPathContext* ctx, LeptrisNode* node, XPathASTNode* test)
231
223
  /* Has prefix (e.g., "ns1:*") - match namespace */
232
224
  size_t prefix_len = colon - test->value;
233
225
 
234
- const char* test_uri = ctx
235
- ? leptris_xpath_ns_lookup(
236
- (const struct leptris_xpath_ns_map*)ctx->ns_set,
237
- test->value, prefix_len)
238
- : NULL;
226
+ const char* test_uri = xpath_expr_prefix_uri(ctx, test->value, prefix_len);
239
227
  if (test_uri) {
240
228
  const char* node_uri =
241
229
  leptris_element_get_namespace_uri(elem);
@@ -1188,11 +1176,7 @@ struct leptris_xpath_result* evaluate_location_path(XPathContext* ctx,
1188
1176
  * default). Unbound prefix falls back to the
1189
1177
  * literal comparison. */
1190
1178
  if (names_match && test_prefix) {
1191
- const char* test_uri = ctx
1192
- ? leptris_xpath_ns_lookup(
1193
- (const struct leptris_xpath_ns_map*)ctx->ns_set,
1194
- test_prefix, strlen(test_prefix))
1195
- : NULL;
1179
+ const char* test_uri = xpath_expr_prefix_uri(ctx, test_prefix, strlen(test_prefix));
1196
1180
  if (test_uri) {
1197
1181
  const char* root_uri =
1198
1182
  leptris_element_get_namespace_uri(root);
@@ -3311,7 +3311,10 @@ static XPathASTNode* parse_location_path(XPathParser* parser) {
3311
3311
 
3312
3312
  ast_node_add_child(node, desc_step);
3313
3313
 
3314
- return node;
3314
+ /* Continue the path after the fused star step: the
3315
+ * fast path used to return bare, leaving a following
3316
+ * SLASH unconsumed (parse error at expression end). */
3317
+ return parse_path_continuation(parser, node);
3315
3318
  }
3316
3319
 
3317
3320
  /* General case: Add descendant-or-self::node() step */