leptris 1.9.313.0-arm-linux → 1.9.317.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 (28) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -0
  3. data/Rakefile +1 -1
  4. data/lib/leptris/version.rb +1 -1
  5. data/lib/libleptris.so +0 -0
  6. data/vendor-src/README.md +1 -1
  7. data/vendor-src/libleptris/CHANGELOG.md +92 -0
  8. data/vendor-src/libleptris/CMakeLists.txt +1 -1
  9. data/vendor-src/libleptris/bindings/rust/descriptor/src/lib.rs +6 -0
  10. data/vendor-src/libleptris/bindings/rust/descriptor/tests/layout.rs +1 -0
  11. data/vendor-src/libleptris/cli/commands/xquery.c +25 -2
  12. data/vendor-src/libleptris/src/include/leptris/descriptor.h +8 -1
  13. data/vendor-src/libleptris/src/leptris/descriptor/plan.c +46 -5
  14. data/vendor-src/libleptris/src/leptris/leptris_internal.h +19 -0
  15. data/vendor-src/libleptris/src/leptris/xpath/evaluator.c +12 -0
  16. data/vendor-src/libleptris/src/leptris/xpath/evaluator_operators.c +276 -24
  17. data/vendor-src/libleptris/src/leptris/xpath/functions.c +35 -0
  18. data/vendor-src/libleptris/src/leptris/xpath/functions_ext31.c +158 -28
  19. data/vendor-src/libleptris/src/leptris/xpath/parser.c +48 -8
  20. data/vendor-src/libleptris/src/leptris/xpath/xpath_public.c +19 -0
  21. data/vendor-src/libleptris/src/leptris/xquery/xquery.c +16 -0
  22. data/vendor-src/libleptris/test/CMakeLists.txt +1 -0
  23. data/vendor-src/libleptris/test/abi/test_descriptor.cpp +141 -0
  24. data/vendor-src/libleptris/test/parser/test_whitespace_shape.cpp +153 -0
  25. data/vendor-src/libleptris/test/xquery/test_qt3.cpp +6 -6
  26. data/vendor-src/libleptris/test/xquery/test_xquery.cpp +134 -5
  27. data/vendor-src/libleptris/vcpkg.json +1 -1
  28. metadata +2 -1
@@ -48,6 +48,10 @@ static int str_eq_coll(const char* a, const char* b,
48
48
  extern struct leptris_xpath_result* xpath_evaluate(XPathContext* context,
49
49
  XPathASTNode* ast);
50
50
  extern char* get_node_text(void* node);
51
+ /* evaluator_operators.c — element members keep their markup (#181). */
52
+ extern char* ctor_member_markup(void* node);
53
+ /* carrier-by-pointer decode (fold-left-009/016); defined below. */
54
+ void* xpath_carrier_node_of(const char* s);
51
55
 
52
56
  /* ---- sequence plumbing ---- */
53
57
 
@@ -65,6 +69,20 @@ static struct leptris_xpath_result* seq_new(void) {
65
69
  }
66
70
 
67
71
  static void seq_push_str(struct leptris_xpath_result* seq, const char* s) {
72
+ /* carrier-by-pointer: element carriers pushed into a result
73
+ * sequence decode to their MARKUP — the members re-enter
74
+ * rendering/deep-equal as markup strings (identity-critical
75
+ * round-trips — fold accumulators — never route through here). */
76
+ void* cn = xpath_carrier_node_of(s ? s : "");
77
+ if (cn) {
78
+ char* m = ctor_member_markup(cn);
79
+ s = m ? m : "";
80
+ XPathTextNode* tn =
81
+ xpath_synth_text(s, strlen(s));
82
+ if (tn) xpath_nodeset_add(seq->value.nodeset_value, tn);
83
+ free(m);
84
+ return;
85
+ }
68
86
  XPathTextNode* tn =
69
87
  xpath_synth_text(s ? s : "", s ? strlen(s) : 0);
70
88
  if (tn) xpath_nodeset_add(seq->value.nodeset_value, tn);
@@ -330,10 +348,33 @@ static char** collect_items_raw(XPathContext* ctx, XPathASTNode** args,
330
348
  void* nd = ns->nodes[k];
331
349
  if (XPATH_NODE_TYPE(nd) == LEPTRIS_NODE_TEXT) {
332
350
  const char* c = ((XPathTextNode*)nd)->content;
333
- items[cnt++] = leptris_strdup(c ? c : "");
351
+ /* carrier-by-pointer: element carriers recover
352
+ * their markup for the item string. */
353
+ void* cn = xpath_carrier_node_of(c ? c : "");
354
+ if (cn) {
355
+ char* m = ctor_member_markup(cn);
356
+ items[cnt++] = m ? m : leptris_strdup("");
357
+ } else {
358
+ items[cnt++] = leptris_strdup(c ? c : "");
359
+ }
334
360
  } else {
335
- char* t = get_node_text(nd);
336
- items[cnt++] = t ? t : leptris_strdup("");
361
+ /* carrier-by-pointer: real ELEMENT members ride
362
+ * their NODE POINTER so callback identity (intersect
363
+ * dedup, fold-left-009/016) survives the channel.
364
+ * ONLY elements: synthetic attribute/namespace nodes
365
+ * are heap-owned by this nodeset — a pointer carrier
366
+ * would dangle once it is freed (ASAN UAF in
367
+ * fn-subsequence); they keep the markup snapshot. */
368
+ if ((int)XPATH_NODE_TYPE(nd) ==
369
+ (int)LEPTRIS_NODE_TYPE_ELEMENT) {
370
+ char pc[24];
371
+ snprintf(pc, sizeof(pc), "\x03P%016llx",
372
+ (unsigned long long)(uintptr_t)nd);
373
+ items[cnt++] = leptris_strdup(pc);
374
+ } else {
375
+ char* t = ctor_member_markup(nd);
376
+ items[cnt++] = t ? t : leptris_strdup("");
377
+ }
337
378
  }
338
379
  }
339
380
  } else if (r->type == XPATH_RESULT_NUMBER) {
@@ -5259,8 +5300,9 @@ static struct leptris_xpath_result* fn_filter(XPathContext* ctx,
5259
5300
  }
5260
5301
 
5261
5302
  /* Decode a fold accumulator carrier into the final result:
5262
- * \x03B boolean, \x03E empty sequence, \x03M member sequence,
5263
- * scalar marks stripped for the string result. */
5303
+ * \x03B boolean, \x03E empty sequence, \x03P node pointer,
5304
+ * \x03M member sequence, scalar marks stripped for the string
5305
+ * result. */
5264
5306
  static struct leptris_xpath_result* fold_result_of(char* acc) {
5265
5307
  struct leptris_xpath_result* out = NULL;
5266
5308
  if (acc && acc[0] == '\x03') {
@@ -5283,6 +5325,25 @@ static struct leptris_xpath_result* fold_result_of(char* acc) {
5283
5325
  }
5284
5326
  return out;
5285
5327
  }
5328
+ if (mk == 'P') {
5329
+ /* carrier-by-pointer: the fold result IS the node —
5330
+ * path steps and text() resolve on the real node
5331
+ * (fold-left-016's $result/text()). */
5332
+ void* cn = xpath_carrier_node_of(acc);
5333
+ free(acc);
5334
+ out = xpath_result_new(XPATH_RESULT_NODESET);
5335
+ if (out) {
5336
+ out->value.nodeset_value = xpath_nodeset_new();
5337
+ if (!out->value.nodeset_value) {
5338
+ xpath_result_free(out);
5339
+ return NULL;
5340
+ }
5341
+ if (cn)
5342
+ xpath_nodeset_add(out->value.nodeset_value,
5343
+ (LeptrisNode*)cn);
5344
+ }
5345
+ return out;
5346
+ }
5286
5347
  if (mk == 'M') {
5287
5348
  char** mem = NULL;
5288
5349
  size_t mn = 0;
@@ -5294,6 +5355,17 @@ static struct leptris_xpath_result* fold_result_of(char* acc) {
5294
5355
  out->value.nodeset_value->owns_synthetic_text = 1;
5295
5356
  for (size_t j = 0; j < mn && out->value.nodeset_value;
5296
5357
  j++) {
5358
+ /* carrier-by-pointer members decode to
5359
+ * their NODE, before the generic mark
5360
+ * strip could eat the pointer. */
5361
+ void* cn = xpath_carrier_node_of(mem[j]);
5362
+ if (cn) {
5363
+ xpath_nodeset_add(
5364
+ out->value.nodeset_value,
5365
+ (LeptrisNode*)cn);
5366
+ free(mem[j]);
5367
+ continue;
5368
+ }
5297
5369
  const char* body = mem[j];
5298
5370
  size_t bl = strlen(body);
5299
5371
  if (body[0] == '\x03' && bl >= 2) {
@@ -5374,6 +5446,17 @@ static char* fn_item_arg_string(struct leptris_xpath_result* r) {
5374
5446
  const char* mc = ((XPathTextNode*)nd)->content;
5375
5447
  if (mc && mc[0] == '\x03') return leptris_strdup(mc);
5376
5448
  }
5449
+ /* carrier-by-pointer: a lone ELEMENT rides its pointer —
5450
+ * the string-value fallback collapses every element to its
5451
+ * text and node identity dies (fold-left-016's context
5452
+ * arg). seq_carrier_of only covers count >= 2. */
5453
+ if ((int)XPATH_NODE_TYPE(nd) ==
5454
+ (int)LEPTRIS_NODE_TYPE_ELEMENT) {
5455
+ char pc[24];
5456
+ snprintf(pc, sizeof(pc), "\x03P%016llx",
5457
+ (unsigned long long)(uintptr_t)nd);
5458
+ return leptris_strdup(pc);
5459
+ }
5377
5460
  }
5378
5461
  /* Multi-item all-text results ride the sequence carrier so the
5379
5462
  * next call's params bind one node per member (for-each-pair
@@ -5583,16 +5666,31 @@ char* xpath_seq_carrier_of(struct leptris_xpath_result* vr) {
5583
5666
  void* b);
5584
5667
  b = xpath_map_builder_new();
5585
5668
  if (!b) return NULL;
5586
- for (size_t j = 0; j < mns->count; j++)
5587
- if ((int)XPATH_NODE_TYPE(mns->nodes[j]) !=
5588
- (int)LEPTRIS_NODE_TEXT) {
5669
+ for (size_t j = 0; j < mns->count; j++) {
5670
+ char* mc;
5671
+ int mtype = (int)XPATH_NODE_TYPE(mns->nodes[j]);
5672
+ if (mtype == (int)LEPTRIS_NODE_TEXT) {
5673
+ mc = leptris_strdup(
5674
+ ((XPathTextNode*)mns->nodes[j])->content);
5675
+ } else if (mtype == (int)LEPTRIS_NODE_TYPE_ELEMENT) {
5676
+ /* carrier-by-pointer (fold-left-009/016): element
5677
+ * members ride their NODE POINTER, not markup — the
5678
+ * callback's $foundSoFar intersect $this dedups by
5679
+ * node identity, which a reparse can never restore.
5680
+ * The pointer is eval-safe: ctor docs anchor on the
5681
+ * source document (#691), parsed docs outlive the
5682
+ * eval; consumers recover markup or the string value
5683
+ * via xpath_carrier_node_of. */
5684
+ char pc[24];
5685
+ snprintf(pc, sizeof(pc), "\x03P%016llx",
5686
+ (unsigned long long)(uintptr_t)mns->nodes[j]);
5687
+ mc = leptris_strdup(pc);
5688
+ } else {
5589
5689
  struct leptris_xpath_result* rel =
5590
5690
  xpath_map_builder_finish(b);
5591
5691
  if (rel) xpath_result_free(rel);
5592
5692
  return NULL;
5593
5693
  }
5594
- for (size_t j = 0; j < mns->count; j++) {
5595
- const char* mc = ((XPathTextNode*)mns->nodes[j])->content;
5596
5694
  /* Member marks SURVIVE the carrier: the next call's FN
5597
5695
  * binding needs them (declared-fold recursion re-collects
5598
5696
  * typed/untyped items, cbcl-distinct-values-002). The FR
@@ -5600,6 +5698,7 @@ char* xpath_seq_carrier_of(struct leptris_xpath_result* vr) {
5600
5698
  char key[24];
5601
5699
  snprintf(key, sizeof(key), "%zu", j + 1);
5602
5700
  xpath_map_builder_add(b, key, mc ? mc : "");
5701
+ free(mc);
5603
5702
  }
5604
5703
  struct leptris_xpath_result* subr = xpath_map_builder_finish(b);
5605
5704
  char* out = NULL;
@@ -5614,6 +5713,16 @@ char* xpath_seq_carrier_of(struct leptris_xpath_result* vr) {
5614
5713
  return out;
5615
5714
  }
5616
5715
 
5716
+ /* carrier-by-pointer decode (fold-left-009/016): a "\x03P" +
5717
+ * 16-hex carrier resolves to its node, valid for the whole eval
5718
+ * (ctor docs anchor on the source document, #691). NULL when the
5719
+ * string is not a pointer carrier. */
5720
+ void* xpath_carrier_node_of(const char* s) {
5721
+ if (!s || s[0] != '\x03' || s[1] != 'P' || strlen(s) != 18)
5722
+ return NULL;
5723
+ return (void*)(uintptr_t)strtoull(s + 2, NULL, 16);
5724
+ }
5725
+
5617
5726
  static struct leptris_xpath_result* fn_apply(XPathContext* ctx,
5618
5727
  XPathASTNode** args, size_t n) {
5619
5728
  (void)n;
@@ -5647,21 +5756,32 @@ static struct leptris_xpath_result* fn_apply(XPathContext* ctx,
5647
5756
  xpath_result_free(vr);
5648
5757
  /* XDM function conversion: node-valued arguments
5649
5758
  * atomize to their string value (fn-apply-14/15). */
5650
- if (v && v[0] == '<') {
5651
- LeptrisStatus st = LEPTRIS_OK;
5652
- LeptrisDocument nd = leptris_parse_string(
5653
- v, strlen(v), &st);
5654
- if (nd) {
5655
- LeptrisElement rt = leptris_document_root(nd);
5656
- if (rt) {
5657
- const char* sv = leptris_element_text(rt);
5658
- char* c = leptris_strdup(sv ? sv : "");
5659
- if (c) {
5660
- free(v);
5661
- v = c;
5759
+ {
5760
+ void* cn = xpath_carrier_node_of(v);
5761
+ if (cn) {
5762
+ const char* sv =
5763
+ leptris_element_text((LeptrisElement)cn);
5764
+ char* c = leptris_strdup(sv ? sv : "");
5765
+ if (c) {
5766
+ free(v);
5767
+ v = c;
5768
+ }
5769
+ } else if (v && v[0] == '<') {
5770
+ LeptrisStatus st = LEPTRIS_OK;
5771
+ LeptrisDocument nd = leptris_parse_string(
5772
+ v, strlen(v), &st);
5773
+ if (nd) {
5774
+ LeptrisElement rt = leptris_document_root(nd);
5775
+ if (rt) {
5776
+ const char* sv = leptris_element_text(rt);
5777
+ char* c = leptris_strdup(sv ? sv : "");
5778
+ if (c) {
5779
+ free(v);
5780
+ v = c;
5781
+ }
5662
5782
  }
5783
+ leptris_document_free(nd);
5663
5784
  }
5664
- leptris_document_free(nd);
5665
5785
  }
5666
5786
  }
5667
5787
  argv[i] = v;
@@ -5684,10 +5804,20 @@ static struct leptris_xpath_result* fn_apply(XPathContext* ctx,
5684
5804
  /* XDM function conversion: a node-valued argument atomizes
5685
5805
  * to its string value. Node members ride their
5686
5806
  * serialization ("<a>ABC</a>" — the array stores lexical
5687
- * members); parse and take the string value so lower-case#1
5688
- * sees "ABC", not "<a>ABC</a>" (fn-apply-14/15). */
5807
+ * members) or the \x03P pointer carrier; parse/decode and
5808
+ * take the string value so lower-case#1 sees "ABC", not
5809
+ * the member spelling (fn-apply-14/15). */
5689
5810
  for (size_t i = 0; i < argc; i++) {
5690
- if (argv[i] && argv[i][0] == '<') {
5811
+ void* cn = xpath_carrier_node_of(argv[i]);
5812
+ if (cn) {
5813
+ const char* sv =
5814
+ leptris_element_text((LeptrisElement)cn);
5815
+ char* c = leptris_strdup(sv ? sv : "");
5816
+ if (c) {
5817
+ argv[i] = c;
5818
+ conv[i] = c;
5819
+ }
5820
+ } else if (argv[i] && argv[i][0] == '<') {
5691
5821
  LeptrisStatus st = LEPTRIS_OK;
5692
5822
  LeptrisDocument nd = leptris_parse_string(
5693
5823
  argv[i], strlen(argv[i]), &st);
@@ -6687,8 +6817,8 @@ static struct leptris_xpath_result* fn_format_number_plain(
6687
6817
  * result is consumed, so the ctx owned_docs chain cannot carry
6688
6818
  * constructed nodes; the source doc's lifetime is the only owner
6689
6819
  * that outlives the result. */
6690
- static int xq_anchor_on_source(XPathContext* ctx,
6691
- struct leptris_document* anchored) {
6820
+ int xq_anchor_on_source(XPathContext* ctx,
6821
+ struct leptris_document* anchored) {
6692
6822
  struct leptris_document* src = ctx->document;
6693
6823
  if (!src) {
6694
6824
  leptris_document_free(anchored);
@@ -1375,13 +1375,44 @@ static XPathASTNode* parse_path_expr(XPathParser* parser) {
1375
1375
  advance_token(parser);
1376
1376
  if (current_token_is(parser, TOK_LPAREN)) {
1377
1377
  advance_token(parser);
1378
- if (current_token_is(parser, TOK_RPAREN))
1378
+ /* ElementTest/AttributeTest with a NAME
1379
+ * argument: element(id),
1380
+ * attribute(class) — fold-left-016's
1381
+ * selector arms. */
1382
+ if (!current_token_is(parser,
1383
+ TOK_RPAREN)) {
1384
+ XPathToken* argt =
1385
+ current_token(parser);
1386
+ if (!argt ||
1387
+ (argt->type != TOK_NCNAME &&
1388
+ argt->type != TOK_QNAME &&
1389
+ argt->type != TOK_STAR)) {
1390
+ ast_node_free(ts);
1391
+ return NULL;
1392
+ }
1393
+ if (tnl + argt->value_len + 3 <
1394
+ sizeof(tn)) {
1395
+ tn[tnl++] = '(';
1396
+ memcpy(tn + tnl, argt->value,
1397
+ argt->value_len);
1398
+ tnl += argt->value_len;
1399
+ tn[tnl++] = ')';
1400
+ tn[tnl] = 0;
1401
+ }
1379
1402
  advance_token(parser);
1380
- else { ast_node_free(ts); return NULL; }
1381
- if (tnl + 2 < sizeof(tn)) {
1382
- tn[tnl++] = '(';
1383
- tn[tnl++] = ')';
1384
- tn[tnl] = 0;
1403
+ }
1404
+ if (!current_token_is(parser, TOK_RPAREN)) {
1405
+ ast_node_free(ts);
1406
+ return NULL;
1407
+ }
1408
+ advance_token(parser);
1409
+ if (tnl + 2 >= sizeof(tn) ||
1410
+ tn[tnl - 1] != ')') {
1411
+ if (tnl + 2 < sizeof(tn)) {
1412
+ tn[tnl++] = '(';
1413
+ tn[tnl++] = ')';
1414
+ tn[tnl] = 0;
1415
+ }
1385
1416
  }
1386
1417
  break;
1387
1418
  }
@@ -1616,8 +1647,17 @@ static XPathASTNode* parse_path_expr(XPathParser* parser) {
1616
1647
  memcmp(current_token(parser)->value, "element", 7) == 0) ||
1617
1648
  (current_token(parser)->value_len == 9 &&
1618
1649
  memcmp(current_token(parser)->value, "attribute", 9) == 0)) &&
1619
- next && (next->type == TOK_NCNAME ||
1620
- next->type == TOK_QNAME) &&
1650
+ next &&
1651
+ /* The NAME may lex as an operator keyword (div,
1652
+ * mod, ...) — HTML tag names collide with XQuery
1653
+ * operators (<div/>, fold-left-016). Accept any
1654
+ * letter-initial token directly before LBRACE. */
1655
+ ((next->type == TOK_NCNAME ||
1656
+ next->type == TOK_QNAME) ||
1657
+ (next->value_len &&
1658
+ ((next->value[0] >= 'a' && next->value[0] <= 'z') ||
1659
+ (next->value[0] >= 'A' &&
1660
+ next->value[0] <= 'Z')))) &&
1621
1661
  parser->token_pos + 2 < parser->token_count &&
1622
1662
  parser->tokens[parser->token_pos + 2].type == TOK_LBRACE) {
1623
1663
  int is_attr =
@@ -522,6 +522,25 @@ LEPTRIS_API char* leptris_xpath_result_string(LeptrisXPathResult result) {
522
522
  leptris_element_text((LeptrisElement)first);
523
523
  return text ? leptris_strdup(text) : leptris_strdup("");
524
524
  }
525
+ /* carrier-by-pointer (fold-left-009/016): a synth
526
+ * member carrying a node pointer renders the node's
527
+ * string-value (the same contract as a real
528
+ * element). */
529
+ {
530
+ extern void* xpath_carrier_node_of(const char* s);
531
+ const char* raw =
532
+ leptris_xpath_result_node_value(result, 0);
533
+ if (raw && (unsigned char)raw[0] == 0x03 &&
534
+ raw[1] == 'P') {
535
+ LeptrisElement cn =
536
+ (LeptrisElement)xpath_carrier_node_of(raw);
537
+ if (cn) {
538
+ const char* text = leptris_element_text(cn);
539
+ return text ? leptris_strdup(text)
540
+ : leptris_strdup("");
541
+ }
542
+ }
543
+ }
525
544
  const char* v = leptris_xpath_result_node_value(result, 0);
526
545
  return v ? leptris_strdup(v) : leptris_strdup("");
527
546
  }
@@ -2037,6 +2037,22 @@ static struct leptris_xpath_result* xq_fn_thunk(XPathContext* ctx,
2037
2037
  v = (mc && mc[0] == '\x03')
2038
2038
  ? leptris_strdup(mc) : NULL;
2039
2039
  }
2040
+ /* carrier-by-pointer: a lone ELEMENT rides its
2041
+ * pointer — the string-value fallback collapses
2042
+ * every element to its text and node identity
2043
+ * dies (fold-left-016's context arg;
2044
+ * seq_carrier_of only covers count >= 2). */
2045
+ if (!v &&
2046
+ r->value.nodeset_value->count == 1 &&
2047
+ (int)XPATH_NODE_TYPE(
2048
+ r->value.nodeset_value->nodes[0]) ==
2049
+ (int)LEPTRIS_NODE_TYPE_ELEMENT) {
2050
+ char pc[24];
2051
+ snprintf(pc, sizeof(pc), "\x03P%016llx",
2052
+ (unsigned long long)(uintptr_t)
2053
+ r->value.nodeset_value->nodes[0]);
2054
+ v = leptris_strdup(pc);
2055
+ }
2040
2056
  if (!v) v = xpath_to_string(r);
2041
2057
  }
2042
2058
  }
@@ -107,6 +107,7 @@ leptris_add_test(test_dom dom/test_dom.cpp)
107
107
  leptris_add_test(test_element_children dom/test_element_children.cpp)
108
108
  leptris_add_test(test_map_lifecycle dom/test_map_lifecycle.cpp)
109
109
  leptris_add_test(test_simd_count parser/test_simd_count.cpp)
110
+ leptris_add_test(test_ws_shape parser/test_whitespace_shape.cpp)
110
111
  leptris_add_test(test_descriptor abi/test_descriptor.cpp)
111
112
  leptris_add_test(test_document_children dom/test_document_children.cpp)
112
113
  leptris_add_test(test_vtable dom/test_vtable.cpp)
@@ -1594,6 +1594,64 @@ TEST(Plan1551, SerializeRoundTripsThroughTheWalk) {
1594
1594
  leptris_document_free(doc2);
1595
1595
  }
1596
1596
 
1597
+ /* Issue #1565: a CONTENT row inside a NESTED child plan serialized
1598
+ * as an empty-named wrapper element (<w:item><>text</></w:item>).
1599
+ * Content rows emit their text inline at every nesting level. */
1600
+ TEST(Plan1565, NestedContentRowEmitsInlineText) {
1601
+ LeptrisStatus st = LEPTRIS_OK;
1602
+ const char* xml =
1603
+ "<r xmlns:w=\"urn:w\"><w:item>text</w:item></r>";
1604
+ LeptrisDocument doc = leptris_parse_string(xml, strlen(xml), &st);
1605
+ ASSERT_NE(doc, nullptr);
1606
+
1607
+ leptris_child_plan item_row[1] = {};
1608
+ item_row[0].wire_name = "item";
1609
+ item_row[0].kind = LEPTRIS_PLAN_KIND_NESTED;
1610
+ item_row[0].child_plan_index = 1;
1611
+ item_row[0].ns_form = LEPTRIS_PLAN_NS_EXACT;
1612
+ item_row[0].ns_uri = "urn:w";
1613
+ item_row[0].ns_prefix = "w";
1614
+
1615
+ leptris_child_plan content_row[1] = {};
1616
+ content_row[0].wire_name = "";
1617
+ content_row[0].kind = LEPTRIS_PLAN_KIND_CONTENT;
1618
+ content_row[0].type_tag = 2;
1619
+ content_row[0].child_plan_index = -1;
1620
+
1621
+ leptris_element_plan plans[2] = {};
1622
+ plans[0].element_name = "r";
1623
+ plans[0].child_count = 1;
1624
+ plans[0].child_plans = item_row;
1625
+ plans[0].ns_form = LEPTRIS_PLAN_NS_EXACT;
1626
+ plans[0].ns_uri = "urn:w";
1627
+ plans[0].ns_prefix = "w";
1628
+ plans[1].element_name = "item";
1629
+ plans[1].child_count = 1;
1630
+ plans[1].child_plans = content_row;
1631
+ plans[1].flags = LEPTRIS_PLAN_FLAG_MIXED_CONTENT;
1632
+ plans[1].ns_form = LEPTRIS_PLAN_NS_EXACT;
1633
+ plans[1].ns_uri = "urn:w";
1634
+ plans[1].ns_prefix = "w";
1635
+
1636
+ leptris_plan_spec spec = {};
1637
+ spec.abi_version = leptris_plan_abi_version();
1638
+ spec.plan_count = 2;
1639
+ spec.plans = plans;
1640
+
1641
+ LeptrisPlan plan = leptris_plan_build(&spec, &st);
1642
+ ASSERT_NE(plan, nullptr);
1643
+ LeptrisPlanResult r =
1644
+ leptris_plan_walk(doc, leptris_document_root(doc), plan, &st);
1645
+ ASSERT_NE(r, nullptr);
1646
+ char* out = leptris_plan_serialize(plan, r, &st);
1647
+ ASSERT_NE(out, nullptr);
1648
+ EXPECT_STREQ(out, "<w:r xmlns:w=\"urn:w\"><w:item>text</w:item></w:r>");
1649
+ leptris_free_string(out);
1650
+ leptris_plan_result_free(r);
1651
+ leptris_plan_free(plan);
1652
+ leptris_document_free(doc);
1653
+ }
1654
+
1597
1655
  TEST(Plan1551, TextAndAttributeValuesAreEscaped) {
1598
1656
  LeptrisStatus st = LEPTRIS_OK;
1599
1657
  const char* xml =
@@ -1696,3 +1754,86 @@ TEST(Plan1551, ChildrenEmitInDocumentOrderAcrossRows) {
1696
1754
  leptris_plan_free(plan);
1697
1755
  leptris_document_free(doc);
1698
1756
  }
1757
+
1758
+ // ---- #1560: unqualified-only ns form -------------------------------
1759
+ // UNQUALIFIED matches the WRITTEN spelling: a child row binds
1760
+ // children with no prefix regardless of the effective namespace
1761
+ // URI, and refuses prefixed spellings. An unprefixed child binds
1762
+ // under both a namespace-less document and a default-xmlns
1763
+ // document (whose children inherit the default namespace — NS_NONE
1764
+ // drops them); a p:child never binds (ANY would accept it — the
1765
+ // superset lutaml-model#932 had to settle for). Round-trip through
1766
+ // the serializer agrees on all three shapes: the serializer emits
1767
+ // prefix declarations only, so a default-ns child serializes bare —
1768
+ // keying on the spelling, not the URI, is what keeps the re-walk
1769
+ // in agreement.
1770
+ TEST(Plan1560, UnqualifiedNsFormBindsNoPrefixSpellings) {
1771
+ LeptrisStatus st = LEPTRIS_OK;
1772
+
1773
+ leptris_child_plan kids[1] = {};
1774
+ kids[0].wire_name = "child";
1775
+ kids[0].kind = LEPTRIS_PLAN_KIND_SCALAR;
1776
+ kids[0].type_tag = 1;
1777
+ kids[0].child_plan_index = -1;
1778
+ kids[0].ns_form = LEPTRIS_PLAN_NS_UNQUALIFIED;
1779
+ leptris_element_plan plans[1] = {};
1780
+ plans[0].element_name = "root";
1781
+ plans[0].ns_form = LEPTRIS_PLAN_NS_ANY;
1782
+ plans[0].child_count = 1;
1783
+ plans[0].child_plans = kids;
1784
+ leptris_plan_spec spec = {};
1785
+ spec.abi_version = leptris_plan_abi_version();
1786
+ spec.plan_count = 1;
1787
+ spec.plans = plans;
1788
+ LeptrisPlan plan = leptris_plan_build(&spec, &st);
1789
+ ASSERT_NE(plan, nullptr);
1790
+
1791
+ struct {
1792
+ const char* xml;
1793
+ const char* value; /* NULL = the row must NOT bind */
1794
+ } shapes[] = {
1795
+ {"<root><child>none</child></root>", "none"},
1796
+ {"<root xmlns=\"urn:d\"><child>default</child></root>", "default"},
1797
+ {"<root xmlns:p=\"urn:p\"><p:child>prefixed</p:child></root>", NULL},
1798
+ };
1799
+ for (const auto& sh : shapes) {
1800
+ SCOPED_TRACE(sh.xml);
1801
+ LeptrisDocument doc =
1802
+ leptris_parse_string(sh.xml, strlen(sh.xml), &st);
1803
+ ASSERT_NE(doc, nullptr);
1804
+ LeptrisElement root = leptris_document_root(doc);
1805
+ LeptrisPlanResult r = leptris_plan_walk(doc, root, plan, &st);
1806
+ ASSERT_NE(r, nullptr);
1807
+ if (sh.value == NULL) {
1808
+ EXPECT_EQ(leptris_plan_value_count(r), 0u);
1809
+ } else {
1810
+ ASSERT_EQ(leptris_plan_value_count(r), 1u);
1811
+ EXPECT_STREQ(leptris_plan_value_string(
1812
+ leptris_plan_value_at(r, 0)),
1813
+ sh.value);
1814
+ }
1815
+ /* Round-trip: serialize the walk, re-parse, re-walk — the
1816
+ * bound values agree on every shape. */
1817
+ char* out = leptris_plan_serialize(plan, r, &st);
1818
+ leptris_plan_result_free(r);
1819
+ ASSERT_NE(out, nullptr);
1820
+ LeptrisDocument doc2 = leptris_parse_string(out, strlen(out), &st);
1821
+ leptris_free_string(out);
1822
+ ASSERT_NE(doc2, nullptr);
1823
+ LeptrisPlanResult r2 =
1824
+ leptris_plan_walk(doc2, leptris_document_root(doc2), plan, &st);
1825
+ ASSERT_NE(r2, nullptr);
1826
+ if (sh.value == NULL) {
1827
+ EXPECT_EQ(leptris_plan_value_count(r2), 0u);
1828
+ } else {
1829
+ ASSERT_EQ(leptris_plan_value_count(r2), 1u);
1830
+ EXPECT_STREQ(leptris_plan_value_string(
1831
+ leptris_plan_value_at(r2, 0)),
1832
+ sh.value);
1833
+ }
1834
+ leptris_plan_result_free(r2);
1835
+ leptris_document_free(doc2);
1836
+ leptris_document_free(doc);
1837
+ }
1838
+ leptris_plan_free(plan);
1839
+ }