leptris 1.9.337.0-arm-linux → 1.9.340.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: eb4692fe1795e30db147e9cd544a2a1480cf343710910ff22a1a89edabe1f716
4
- data.tar.gz: ab71586de0b8ab37545e887522906e12d63faa0b391e5b4f578bb66e90640186
3
+ metadata.gz: 9d0e0d99be47e5b77f7b3d482d683d3e8247199258dd61ecaa733d4b25f54464
4
+ data.tar.gz: 2d34476b27c4e6d026ddeab49c9f11dfb4c9f9efc2258ac1b305bacbe6f81cac
5
5
  SHA512:
6
- metadata.gz: b7baf55e9c65bbb54b4bd269cd9b8ea8df3ea4b321c795af87d3de2a7741377f88f764bd45389d63c2186b7d2e36cccbda4737c75ebbf1c341f3ba9331f6adc3
7
- data.tar.gz: 3a1834d9507a6a3669a18d18f168c501af122e2d763b37d5ab58ce9159779106619252d428abdd34ff616c26fec626a3e506cf4123a8cc43c217fffa4b9f4315
6
+ metadata.gz: 022ded1665d829afa6731228fc4ec892adc671789fd6fed3a8b42bba937fe0b8f891b3ace3a7a0ab52410d21f9935da523a0aa0a4d7ea17fff0a6712f1287e04
7
+ data.tar.gz: d3ebeea50843ee2fcb31685aa21704fbfc20deb4e2bb2a7da85da5eace64bb38a2f63eba805ffb7fe8e5762350adb8a2183dc16061aaca9d6d54ac65a16ab29c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## [1.9.340.0] - 2026-10-11
2
+
3
+ ### Added — engine sync (libleptris 1.9.338-1.9.340)
4
+
5
+ - **`leptris_element_add_child_addr_installed` (1.9.340)**: the
6
+ addr-attach twin returning the EFFECTIVE installed address — a
7
+ foreign node adopted by copy (#1528) reports the copy's address,
8
+ which callers must use for every later handle (the dangling-
9
+ wrapper mechanism behind the Windows `fast_element_xml`
10
+ segfault). Audit 385/384.
11
+
12
+ ### Fixed — engine sync
13
+
14
+ - 1.9.339: cycle-creating reparents rejected (#1636) — appending
15
+ a node into its own descendant subtree built parent cycles that
16
+ unbounded the serializer's recursion.
17
+ - 1.9.338: in-body drops table-structure start tags (#1634);
18
+ indent_html ext option (#1635).
19
+
20
+ Note: the #425/#426 plan faces (engine PR #1645, merged) were cut
21
+ AFTER the v1.9.340 tag — they ride the next engine release.
22
+
1
23
  ## [1.9.337.0] - 2026-10-11
2
24
 
3
25
  ### Added — engine sync (libleptris 1.9.337)
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.337"
11
+ LIBLEPTRIS_VERSION = "1.9.340"
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
data/lib/leptris/html.rb CHANGED
@@ -21,6 +21,78 @@
21
21
  # elements serialize with the HTML5-legal trailing slash).
22
22
  module Leptris
23
23
  module HTML
24
+ # WHATWG fragment parsing with a context element (#1634 /
25
+ # moxml#353). Composed over the WHATWG lane: the fragment runs
26
+ # inside the context element's ancestor chain, so tree
27
+ # construction lands in the right insertion mode (body context
28
+ # keeps <title>/<meta> at fragment top level; table contexts
29
+ # take the in-table rules). The wrapper document stays alive
30
+ # for the fragment's lifetime - children address its pool.
31
+ class Fragment
32
+ # chains are the ancestors the parser opens before the
33
+ # fragment: the innermost element carries the children
34
+ TABLE_CHAINS = {
35
+ table: %w[table],
36
+ tbody: %w[table tbody],
37
+ thead: %w[table thead],
38
+ tfoot: %w[table tfoot],
39
+ tr: %w[table tbody tr],
40
+ td: %w[table tbody tr td],
41
+ th: %w[table tbody tr th],
42
+ caption: %w[table caption],
43
+ colgroup: %w[table colgroup],
44
+ }.freeze
45
+
46
+ def initialize(document, chain)
47
+ # The wrapper document always carries a body (explicit tag
48
+ # or synthesis); table chains nest under it.
49
+ @document = document
50
+ el = first_element_named(document.root, "body")
51
+ chain.each do |tag|
52
+ break unless el
53
+ el = first_element_named(el, tag)
54
+ end
55
+ @context = el
56
+ end
57
+
58
+ # The parsed top-level nodes (text, elements, comments) in
59
+ # tree order - the fragment's children, Nokogiri's
60
+ # DocumentFragment#children shape.
61
+ def children
62
+ @context ? @context.children.to_a : []
63
+ end
64
+
65
+ def each(&block)
66
+ children.each(&block)
67
+ end
68
+
69
+ include Enumerable
70
+
71
+ def size
72
+ children.size
73
+ end
74
+
75
+ def empty?
76
+ children.empty?
77
+ end
78
+
79
+ # The fragment serialized as its children joined (HTML
80
+ # method per node; text verbatim).
81
+ def to_html
82
+ children.map do |c|
83
+ c.is_a?(Leptris::XML::Text) ? c.content : c.to_html
84
+ end.join
85
+ end
86
+
87
+ private
88
+
89
+ def first_element_named(parent, name)
90
+ parent.children.find do |c|
91
+ c.is_a?(Leptris::XML::Element) && c.name == name
92
+ end
93
+ end
94
+ end
95
+
24
96
  module_function
25
97
 
26
98
  # Nokogiri::HTML shape: the default lane is html4 (byte-parity
@@ -29,6 +101,25 @@ module Leptris
29
101
  Leptris::XML.parse_html(html, mode: :html4)
30
102
  end
31
103
 
104
+ # WHATWG fragment parse (body context by default; the table
105
+ # contexts wrap their ancestor chain). Matches
106
+ # Nokogiri::HTML5.fragment semantics on the head-sweep and
107
+ # foster-parenting divergence set (verified against the
108
+ # html5lib trees).
109
+ def parse_fragment(html, context: :body)
110
+ chain = context == :body ? ["body"] : Fragment::TABLE_CHAINS.fetch(context) do
111
+ raise ArgumentError,
112
+ "context must be :body or a table context " \
113
+ "(#{(Fragment::TABLE_CHAINS.keys + [:body]).join(', ')}), " \
114
+ "got #{context.inspect}"
115
+ end
116
+ prefix = "<body>#{chain.map { |t| "<#{t}>" }.join}"
117
+ suffix = "#{chain.reverse.map { |t| "</#{t}>" }.join}</body>"
118
+ wrapped = "#{prefix}#{html}#{suffix}"
119
+ Fragment.new(Leptris::HTML5.parse(wrapped),
120
+ chain.first == "body" ? chain.drop(1) : chain)
121
+ end
122
+
32
123
  # Fresh document with the HTML 4.01 Transitional doctype preset
33
124
  # (Nokogiri::HTML::Builder's .doc carries the same). Pass
34
125
  # +doctype: nil+ for a bare document.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leptris
4
- VERSION = "1.9.337.0"
4
+ VERSION = "1.9.340.0"
5
5
  end
@@ -546,9 +546,10 @@ class Leptris::XML::Document
546
546
  # entity escaping per HTML rules, the DOCTYPE emitted first.
547
547
  # Walks the tree in Ruby — the engine-side serialization mode is
548
548
  # the perf headroom this face gates on.
549
- def to_html
549
+ def to_html(indent: 0, indent_text: nil)
550
550
  raise Leptris::XML::UseAfterFreeError if @freed.state == :freed
551
- Leptris::XML::Serialization.document_html(c_ptr)
551
+ Leptris::XML::Serialization.document_html(
552
+ c_ptr, indent: indent, indent_text: indent_text)
552
553
  end
553
554
 
554
555
  def save(path, mode: :xml, **opts)
@@ -205,7 +205,12 @@ module Leptris
205
205
  # libleptris 1.9.225 (#1311): tri-state — 0 = the
206
206
  # document's default method, 1 = force HTML, -1 =
207
207
  # force XML (to_xml on an HTML document).
208
- :html_method, :int
208
+ :html_method, :int,
209
+ # libleptris 1.9.xxx (#1635): 1 = the html layout
210
+ # nests with the indent machinery (libxml2 format
211
+ # mode); 0 = the §16.2 newline-only shape. Appended —
212
+ # the sized entry keeps older allocations zeroed.
213
+ :indent_html, :int
209
214
  end
210
215
 
211
216
  # Mirrors LeptrisParseOptions (libleptris >= 1.9.0 carries the
@@ -883,6 +888,13 @@ attach_function :leptris_parse_string,
883
888
  # semantics and status contract as the pointer face.
884
889
  attach_function :leptris_element_add_child_addr,
885
890
  [:ulong_long, :ulong_long], :leptris_status
891
+ # #1636: the addr-attach twin returning the EFFECTIVE
892
+ # installed child address — a foreign node is adopted by
893
+ # copy (#1528) and the caller must use the copy's address
894
+ # for every later handle. installed may be NULL
895
+ # (status-only).
896
+ attach_function :leptris_element_add_child_addr_installed,
897
+ [:ulong_long, :ulong_long, :pointer], :leptris_status
886
898
  # Fused create+append (libleptris 1.9.153): one document
887
899
  # resolution, identical tree semantics to the two-call pair.
888
900
  attach_function :leptris_element_create_child,
@@ -60,10 +60,30 @@ module Leptris::XML::Serialization
60
60
  # one FFI fast-path dispatch per child.
61
61
  # Document HTML serialization (libleptris 1.9.225, #1311): the
62
62
  # native HTML mode — voids unclosed, raw-text script/style,
63
- # explicit closes, no declaration, DOCTYPE first.
64
- def self.document_html(c_ptr)
63
+ # explicit closes, no declaration, DOCTYPE first. With +indent+
64
+ # (spaces per level) or +indent_text+ (a unit string like "\t"),
65
+ # the ext serializer runs method="html" layout over the standard
66
+ # indent machinery (moxml#354 / leptris#1635): line breaks around
67
+ # block/element children per the HTML element table, raw-text and
68
+ # mixed content verbatim.
69
+ def self.document_html(c_ptr, indent: 0, indent_text: nil)
70
+ if indent.to_i.zero? && indent_text.nil?
71
+ return Leptris::XML::FFI.read_owned_string(
72
+ Leptris::XML::FFI.leptris_document_serialize_html(c_ptr, nil))
73
+ end
74
+
75
+ opts, _encoding_anchor = build_options(indent: indent, no_decl: true)
76
+ ext = Leptris::XML::FFI::SerializeExtStruct.new
77
+ ext[:html_method] = 1
78
+ ext[:indent_html] = 1
79
+ unit_anchor = nil
80
+ if indent_text
81
+ unit_anchor = ::FFI::MemoryPointer.from_string(indent_text.to_s)
82
+ ext[:indent_unit] = unit_anchor
83
+ end
65
84
  Leptris::XML::FFI.read_owned_string(
66
- Leptris::XML::FFI.leptris_document_serialize_html(c_ptr, nil))
85
+ Leptris::XML::FFI.leptris_document_serialize_ext_sized(
86
+ c_ptr, opts.pointer, ext.pointer, ext.size))
67
87
  end
68
88
 
69
89
  # Element-level HTML mode through the ext serializer (the
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.337
4
+ - libleptris v1.9.340
5
5
  - utf8proc v2.11.0
6
6
 
7
7
  Rebuild by hand:
@@ -1,5 +1,55 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.9.340] - 2026-10-11
4
+
5
+ ### Added
6
+
7
+ - **`leptris_element_add_child_addr_installed` — the add_child_addr
8
+ twin reporting the effective installed address (leptris-ruby#1636,
9
+ PR #1642).** `add_child_addr` is status-only: a foreign node is
10
+ adopted by copy (#1528) and the installed copy's address is
11
+ dropped, so callers kept addressing the foreign original — which
12
+ dies with its document (the dangling-wrapper mechanism behind the
13
+ Windows `fast_element_xml` segfault). The twin returns the
14
+ effective node: same-document attaches return the argument
15
+ unchanged (zero extra cost), foreign attaches return the copy the
16
+ caller must rebase its wrapper to. `installed_addr = NULL` is the
17
+ status-only form; the status contract is identical to
18
+ `add_child_addr`, and the #1639 cycle rejection rides the append.
19
+
20
+
21
+
22
+ ## [1.9.339] - 2026-10-11
23
+
24
+ ### Fixed
25
+
26
+ - **reject cycle-creating reparents (#1636, PR #1640).** The
27
+ Windows `fast_element_xml` CFUNC segfault in leptris 1.9.33x:
28
+ mutation could append a node into its own descendant subtree,
29
+ building a parent cycle — any serialize then recursed without
30
+ bound and the process died (the `_chkstk` signature in the
31
+ metanorma-standoc dump is the stack probe hitting the exhausted
32
+ stack; reproduced deterministically under ASAN). All four
33
+ reparenting mutators — `append_child`, `prepend_child`,
34
+ `insert_before`, `insert_after`, and `add_child_addr` through
35
+ the append contract — now reject the cycle edge with
36
+ `LEPTRIS_ERROR_INVALID_ARG`. Legal appends are byte-identical
37
+ (spec-pinned).
38
+
39
+
40
+
41
+ ## [1.9.338] - 2026-10-11
42
+
43
+ ### Added
44
+
45
+ - indent_html ext option — nested HTML indent (#1635) (serialize)
46
+
47
+ ### Fixed
48
+
49
+ - in-body drops the table-structure start tags (#1634) (html)
50
+
51
+
52
+
3
53
  ## [1.9.337] - 2026-10-11
4
54
 
5
55
  ### Added
@@ -3,7 +3,7 @@
3
3
  cmake_minimum_required(VERSION 3.20)
4
4
 
5
5
  project(leptris
6
- VERSION 1.9.337
6
+ VERSION 1.9.340
7
7
  DESCRIPTION "Fast XML parser and XPath evaluator in pure C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -360,6 +360,14 @@ typedef struct {
360
360
  * 1 = force HTML on any document, -1 = force XML (to_xml on an
361
361
  * HTML document). XSLT method="html" maps to 1. */
362
362
  int html_method;
363
+ /* 1 = the html-method layout NESTS with the indent machinery
364
+ * (spaces / unit) like libxml2 htmlNodeDumpFormatOutput
365
+ * format=1 (#1635): leads before block children and close tags,
366
+ * mixed follows actual text children, raw text stays verbatim.
367
+ * 0 = the historical §16.2 newline-only shape (XSLT
368
+ * method="html"). Meaningful only with html_method=1 and
369
+ * options->indent > 0. */
370
+ int indent_html;
363
371
  } LeptrisSerializeExtOptions;
364
372
 
365
373
  /* ============================================================================
@@ -2158,6 +2158,18 @@ LEPTRIS_API LeptrisStatus leptris_element_set_name(LeptrisElement elem, const ch
2158
2158
  * status contract as leptris_element_append_child. */
2159
2159
  LEPTRIS_API LeptrisStatus leptris_element_add_child_addr(uintptr_t parent_addr,
2160
2160
  uintptr_t child_addr);
2161
+
2162
+ /* #1636: add_child_addr twin returning the EFFECTIVE installed
2163
+ * child address. A same-document attach installs the argument —
2164
+ * installed_addr receives it unchanged; a foreign node is adopted
2165
+ * by copy (#1528) and installed_addr receives the copy's address,
2166
+ * which the caller must use for every later handle. installed_addr
2167
+ * may be NULL (status-only). Same status contract as
2168
+ * add_child_addr.
2169
+ * Memory: the installed node is owned by parent's document. */
2170
+ LEPTRIS_API LeptrisStatus leptris_element_add_child_addr_installed(
2171
+ uintptr_t parent_addr, uintptr_t child_addr,
2172
+ uintptr_t* installed_addr);
2161
2173
  LEPTRIS_API LeptrisStatus leptris_element_append_child(LeptrisElement parent, LeptrisElement child);
2162
2174
 
2163
2175
  /**
@@ -500,9 +500,60 @@ LeptrisStatus leptris_element_add_child_addr(uintptr_t parent_addr,
500
500
  (LeptrisElement)child_addr);
501
501
  }
502
502
 
503
+ LeptrisStatus leptris_element_add_child_addr_installed(
504
+ uintptr_t parent_addr, uintptr_t child_addr,
505
+ uintptr_t* installed_addr) {
506
+ if (!parent_addr || !child_addr) return LEPTRIS_ERROR_NULL_ARG;
507
+ if (installed_addr) *installed_addr = child_addr;
508
+
509
+ /* The same-document fast path installs the argument itself;
510
+ * the foreign gate deep-copies (#1528) and the status-only
511
+ * face drops the copy's address — callers kept addressing the
512
+ * foreign original, which dies with its document (#1636).
513
+ * This face always reports the effective node. */
514
+ LeptrisElement original = (LeptrisElement)child_addr;
515
+ if (leptris_element_get_document(original) ==
516
+ leptris_element_get_document((LeptrisElement)parent_addr)) {
517
+ return leptris_element_append_child(
518
+ (LeptrisElement)parent_addr, original);
519
+ }
520
+
521
+ LeptrisElement installed =
522
+ (LeptrisElement)adopt_for_splice((LeptrisNode*)original,
523
+ leptris_element_get_document(
524
+ (LeptrisElement)parent_addr));
525
+ if (!installed) return LEPTRIS_ERROR_MEMORY;
526
+
527
+ /* Cycle rejection rides the append; report the copy. */
528
+ LeptrisStatus rc = leptris_element_append_child(
529
+ (LeptrisElement)parent_addr, installed);
530
+ if (rc != LEPTRIS_OK) return rc;
531
+ if (installed_addr) *installed_addr = (uintptr_t)installed;
532
+ return LEPTRIS_OK;
533
+ }
534
+
503
535
  LeptrisStatus leptris_element_append_child(LeptrisElement parent, LeptrisElement child) {
504
536
  if (!parent || !child) return LEPTRIS_ERROR_NULL_ARG;
505
537
 
538
+ /* #1636: appending a node into its own descendant subtree
539
+ * builds a parent cycle — every tree walker (serializer
540
+ * first) then recurses without bound and the process dies
541
+ * (_chkstk SEGV on Windows). Parse-built trees cannot cycle
542
+ * (the open stack is a stack); only mutation can. Reject the
543
+ * ancestor edge: walk child's parent chain for parent. The
544
+ * same-document fast path below never sees foreign copies as
545
+ * ancestors, so the walk runs on the caller's node — O(depth),
546
+ * depth bounded by the parse cap. */
547
+ {
548
+ if (parent == child) return LEPTRIS_ERROR_INVALID_ARG;
549
+ LeptrisElement p = leptris_element_parent(parent);
550
+ int guard = 0;
551
+ while (p && guard++ < 8192) {
552
+ if (p == child) return LEPTRIS_ERROR_INVALID_ARG;
553
+ p = leptris_element_parent(p);
554
+ }
555
+ }
556
+
506
557
  /* Single document resolution per mutation (TODO 195c): the
507
558
  * root walk + map lookup was paid three times per append
508
559
  * (twice here, once inside the internal for the tail cache). */
@@ -542,6 +593,13 @@ LeptrisStatus leptris_element_append_child(LeptrisElement parent, LeptrisElement
542
593
  LeptrisStatus leptris_element_prepend_child(LeptrisElement parent, LeptrisElement child) {
543
594
  if (!parent || !child) return LEPTRIS_ERROR_NULL_ARG;
544
595
 
596
+ /* #1636: no cycles — see leptris_element_append_child. */
597
+ if (parent == child) return LEPTRIS_ERROR_INVALID_ARG;
598
+ for (LeptrisElement p = leptris_element_parent(parent);
599
+ p; p = leptris_element_parent(p)) {
600
+ if (p == child) return LEPTRIS_ERROR_INVALID_ARG;
601
+ }
602
+
545
603
  /* #1528: a foreign document's node is adopted by copy, never
546
604
  * spliced raw. */
547
605
  child = (LeptrisElement)adopt_for_splice(
@@ -563,6 +621,19 @@ LeptrisStatus leptris_element_prepend_child(LeptrisElement parent, LeptrisElemen
563
621
  LeptrisStatus leptris_element_insert_before(LeptrisElement sibling, LeptrisElement new_node) {
564
622
  if (!sibling || !new_node) return LEPTRIS_ERROR_NULL_ARG;
565
623
 
624
+ /* #1636: reparenting a node into its own descendant subtree
625
+ * builds a parent cycle — tree walkers recurse unbounded and
626
+ * the process dies. Reject when the new parent position lies
627
+ * under the node itself. */
628
+ if (((LeptrisNode*)new_node)->type == LEPTRIS_NODE_TYPE_ELEMENT) {
629
+ if ((LeptrisElement)sibling == (LeptrisElement)new_node)
630
+ return LEPTRIS_ERROR_INVALID_ARG;
631
+ for (LeptrisElement p = leptris_element_parent(sibling);
632
+ p; p = leptris_element_parent(p)) {
633
+ if (p == (LeptrisElement)new_node)
634
+ return LEPTRIS_ERROR_INVALID_ARG;
635
+ }
636
+ }
566
637
  LeptrisNode* new_node_ptr = (LeptrisNode*)new_node;
567
638
  LeptrisNode* sibling_ptr = (LeptrisNode*)sibling;
568
639
 
@@ -634,7 +705,7 @@ LeptrisStatus leptris_element_insert_before(LeptrisElement sibling, LeptrisEleme
634
705
 
635
706
  /* Set parent (type-dispatching). TODO 155 Phase A: document field
636
707
  * removed; non-root elements reach doc via walk to root. */
637
- if (new_node_ptr->type == LEPTRIS_NODE_TYPE_ELEMENT) {
708
+ if (((LeptrisNode*)new_node)->type == LEPTRIS_NODE_TYPE_ELEMENT) {
638
709
  leptris_element_set_parent((LeptrisElement)new_node_ptr, parent);
639
710
  } else {
640
711
  switch (new_node_ptr->type) {
@@ -660,7 +731,7 @@ LeptrisStatus leptris_element_insert_before(LeptrisElement sibling, LeptrisEleme
660
731
 
661
732
  /* Issue #213: maintain child_count for element children only,
662
733
  * matching leptris_element_append_child_internal. */
663
- if (new_node_ptr->type == LEPTRIS_NODE_TYPE_ELEMENT) {
734
+ if (((LeptrisNode*)new_node)->type == LEPTRIS_NODE_TYPE_ELEMENT) {
664
735
  parent->child_count++;
665
736
  }
666
737
 
@@ -676,6 +747,19 @@ LeptrisStatus leptris_element_insert_before(LeptrisElement sibling, LeptrisEleme
676
747
  LeptrisStatus leptris_element_insert_after(LeptrisElement sibling, LeptrisElement new_node) {
677
748
  if (!sibling || !new_node) return LEPTRIS_ERROR_NULL_ARG;
678
749
 
750
+ /* #1636: reparenting a node into its own descendant subtree
751
+ * builds a parent cycle — tree walkers recurse unbounded and
752
+ * the process dies. Reject when the new parent position lies
753
+ * under the node itself. */
754
+ if (((LeptrisNode*)new_node)->type == LEPTRIS_NODE_TYPE_ELEMENT) {
755
+ if ((LeptrisElement)sibling == (LeptrisElement)new_node)
756
+ return LEPTRIS_ERROR_INVALID_ARG;
757
+ for (LeptrisElement p = leptris_element_parent(sibling);
758
+ p; p = leptris_element_parent(p)) {
759
+ if (p == (LeptrisElement)new_node)
760
+ return LEPTRIS_ERROR_INVALID_ARG;
761
+ }
762
+ }
679
763
  LeptrisNode* new_node_ptr = (LeptrisNode*)new_node;
680
764
  LeptrisNode* sibling_ptr = (LeptrisNode*)sibling;
681
765
 
@@ -731,7 +815,7 @@ LeptrisStatus leptris_element_insert_after(LeptrisElement sibling, LeptrisElemen
731
815
 
732
816
  /* Set parent (type-dispatching). TODO 155 Phase A: document field
733
817
  * removed; non-root elements reach doc via walk to root. */
734
- if (new_node_ptr->type == LEPTRIS_NODE_TYPE_ELEMENT) {
818
+ if (((LeptrisNode*)new_node)->type == LEPTRIS_NODE_TYPE_ELEMENT) {
735
819
  leptris_element_set_parent((LeptrisElement)new_node_ptr, parent);
736
820
  } else {
737
821
  switch (new_node_ptr->type) {
@@ -761,7 +845,7 @@ LeptrisStatus leptris_element_insert_after(LeptrisElement sibling, LeptrisElemen
761
845
  leptris_elem_set_last_child(parent, new_node_ptr);
762
846
  }
763
847
 
764
- if (new_node_ptr->type == LEPTRIS_NODE_TYPE_ELEMENT) {
848
+ if (((LeptrisNode*)new_node)->type == LEPTRIS_NODE_TYPE_ELEMENT) {
765
849
  parent->child_count++;
766
850
  }
767
851
 
@@ -7213,23 +7213,46 @@ static LeptrisDocument html_parse_shared(
7213
7213
  continue;
7214
7214
  }
7215
7215
 
7216
- /* <col>/<colgroup> in body drops - they are
7217
- * table-structure only (tests25:7: <body><col>A keeps
7218
- * just "A"; tests1:109's trailing <colgroup> after
7219
- * </table> vanishes). */
7216
+ /* Table-structure-only start tags in body drop - "in
7217
+ * body" has no insertion rule for caption, col, colgroup,
7218
+ * head, tbody, td, tfoot, th, thead, tr (WHATWG 13.2.6.4
7219
+ * "any other start tag" path: parse error, ignore the
7220
+ * token, its content flows into body; tests25:7
7221
+ * <body><col>A keeps just "A", tests1:109's trailing
7222
+ * <colgroup> after </table> vanishes). Valid inside a
7223
+ * table/colgroup/template context - the in-table machinery
7224
+ * owns them there. */
7220
7225
  if (b.whatwg &&
7221
7226
  (strcmp(name, "col") == 0 ||
7222
- strcmp(name, "colgroup") == 0)) {
7223
- int col_tbl = 0;
7227
+ strcmp(name, "colgroup") == 0 ||
7228
+ strcmp(name, "caption") == 0 ||
7229
+ strcmp(name, "head") == 0 ||
7230
+ strcmp(name, "tbody") == 0 ||
7231
+ strcmp(name, "td") == 0 ||
7232
+ strcmp(name, "tfoot") == 0 ||
7233
+ strcmp(name, "th") == 0 ||
7234
+ strcmp(name, "thead") == 0 ||
7235
+ strcmp(name, "tr") == 0)) {
7236
+ /* Foreign content inserts any start tag (the svg/math
7237
+ * breakout list does not include these names) — the
7238
+ * drop is an "in body" rule only. */
7239
+ int tbl_ctx = h_top_foreign(&b) ? 1 : 0;
7224
7240
  for (size_t d2 = b.depth; d2 > 0; d2--) {
7225
7241
  uint8_t oid2 = b.open_id[d2 - 1];
7226
7242
  if (oid2 == h_id_table || oid2 == h_id_colgroup ||
7227
7243
  oid2 == h_id_template) {
7228
- col_tbl = 1;
7244
+ tbl_ctx = 1;
7229
7245
  break;
7230
7246
  }
7231
7247
  }
7232
- if (!col_tbl) {
7248
+ if (!tbl_ctx) {
7249
+ /* The TOKEN is ignored - surrounding character
7250
+ * tokens keep flowing into body (the html-merge
7251
+ * flush pattern). */
7252
+ if (text < p) {
7253
+ LeptrisTextNode* t = h_text_node(&b, text, p);
7254
+ if (t) h_append(&b, (LeptrisNodeRef)t);
7255
+ }
7233
7256
  while (q < end && *q != '>') q++;
7234
7257
  p = (q < end) ? q + 1 : end;
7235
7258
  text = p;
@@ -48,6 +48,7 @@ SerializeBuffer* buffer_create(int indent_spaces) {
48
48
  buf->indent_spaces = indent_spaces;
49
49
  buf->indent_unit = NULL; /* #633: callers opt in per unit string */
50
50
  buf->html_method = 0;
51
+ buf->indent_html = 0;
51
52
  buf->indent_text = 0;
52
53
  buf->expand_empty = 0;
53
54
  buf->at_line_start = 0;
@@ -135,9 +136,11 @@ void buffer_append_char(SerializeBuffer* buf, char c) {
135
136
 
136
137
  void buffer_append_indent(SerializeBuffer* buf) {
137
138
  if (!buf || buf->indent_spaces <= 0) return;
138
- /* §16.2 html method: newline-only layout — libxml2's HTML dump
139
- * never nests with spaces. */
140
- if (buf->html_method) return;
139
+ /* §16.2 html method: the historical layout is newline-only —
140
+ * libxml2's unindented HTML dump never nests. #1635
141
+ * indent_html opts the html method into the nesting layout
142
+ * (htmlNodeDumpFormatOutput format=1). */
143
+ if (buf->html_method && !buf->indent_html) return;
141
144
 
142
145
  if (buf->indent_unit && buf->indent_unit[0]) {
143
146
  size_t ul = strlen(buf->indent_unit);
@@ -1015,7 +1018,8 @@ void serialize_element_internal(LeptrisElement root_elem, SerializeBuffer* buf,
1015
1018
  * inside a mixed parent is verbatim content: never
1016
1019
  * dropped. HTML mode prints text verbatim (libxml2 has
1017
1020
  * no formatter-owned whitespace there). */
1018
- if (buf->indent_spaces > 0 && !buf->html_method &&
1021
+ if (buf->indent_spaces > 0 &&
1022
+ (!buf->html_method || buf->indent_html) &&
1019
1023
  cur->type == LEPTRIS_NODE_TYPE_TEXT &&
1020
1024
  !((sp > 0) && st[sp - 1].mixed)) {
1021
1025
  LeptrisTextNode* wsn = (LeptrisTextNode*)cur;
@@ -1102,7 +1106,7 @@ void serialize_element_internal(LeptrisElement root_elem, SerializeBuffer* buf,
1102
1106
  * line, like element siblings. Mixed-content parents
1103
1107
  * keep them inline — a PI between text must not move. */
1104
1108
  if (buf->indent_spaces > 0 && sp > 0 && !st[sp - 1].mixed &&
1105
- !buf->html_method &&
1109
+ (!buf->html_method || buf->indent_html) &&
1106
1110
  (cur->type == LEPTRIS_NODE_TYPE_COMMENT ||
1107
1111
  cur->type == LEPTRIS_NODE_TYPE_PI)) {
1108
1112
  buffer_append_indent(buf);
@@ -1183,8 +1187,8 @@ void serialize_element_internal(LeptrisElement root_elem, SerializeBuffer* buf,
1183
1187
  * close into the same single reservation — leaves
1184
1188
  * otherwise pay ~8 capacity-checked appends each
1185
1189
  * (the raw-only guard was why pretty trailed). */
1186
- int pretty0 = buf->indent_spaces > 0 &&
1187
- !buf->html_method && !parent_mixed;
1190
+ int pretty0 = buf->indent_spaces > 0 && !parent_mixed &&
1191
+ (!buf->html_method || buf->indent_html);
1188
1192
  /* HTML mode: zero lead ever; trail follows the
1189
1193
  * after-close break rule (mixed is not a gate). */
1190
1194
  int htrail0 = buf->html_method && !is_root_cur &&
@@ -1619,12 +1623,32 @@ void serialize_element_internal(LeptrisElement root_elem, SerializeBuffer* buf,
1619
1623
  int mixed = 0;
1620
1624
  int close_brk = 0;
1621
1625
  if (buf->html_method) {
1622
- /* §16.2: mixed is not a gate — the site rules own the
1623
- * newlines. mixed=1 keeps ws-only text verbatim. */
1624
- mixed = 1;
1625
1626
  int hf = html_elem_sem_flags(e);
1626
- if (html_break_before_children(e, name, nl, hf))
1627
- buffer_append_newline(buf);
1627
+ if (!buf->indent_html) {
1628
+ /* §16.2 legacy: mixed is not a gate — the site
1629
+ * rules own the newlines. mixed=1 keeps ws-only
1630
+ * text verbatim. */
1631
+ mixed = 1;
1632
+ if (html_break_before_children(e, name, nl, hf))
1633
+ buffer_append_newline(buf);
1634
+ } else {
1635
+ /* #1635 indented HTML: the element takes the block
1636
+ * layout — mixed follows actual text children like
1637
+ * the XML formatter (libxml2 format mode), so the
1638
+ * layout machinery nests; the site rules still own
1639
+ * the newlines. Elements that keep their children
1640
+ * inline (single-child rule) own no whitespace. */
1641
+ int brk_bc = html_break_before_children(e, name, nl, hf);
1642
+ if (brk_bc) {
1643
+ mixed = buf->ws_mixed
1644
+ ? ser_children_have_any_text(fc)
1645
+ : ser_children_have_text(fc);
1646
+ if (!mixed && sp > 0 && st[sp - 1].mixed) mixed = 1;
1647
+ } else {
1648
+ mixed = 1;
1649
+ }
1650
+ if (brk_bc) buffer_append_newline(buf);
1651
+ }
1628
1652
  close_brk = html_break_before_close(e, name, nl, hf);
1629
1653
  } else {
1630
1654
  /* #129 indent_text: the formatter owns ALL whitespace —
@@ -1698,8 +1722,19 @@ void serialize_element_internal(LeptrisElement root_elem, SerializeBuffer* buf,
1698
1722
  const char* pfx2 = leptris_element_get_prefix(pe);
1699
1723
  /* #534: no indent inside a mixed-content element. HTML
1700
1724
  * mode: site-3 newline before the close tag, no spaces. */
1701
- if (buf->html_method) {
1725
+ if (buf->html_method && !buf->indent_html) {
1702
1726
  if (st[sp].close_brk) buffer_append_newline(buf);
1727
+ } else if (buf->html_method) {
1728
+ /* #1635: the last child's after-close break may
1729
+ * already have ended the line — dedup so the close
1730
+ * tag nests without a blank line. */
1731
+ if (st[sp].close_brk && buf->size > 0 &&
1732
+ buf->data[buf->size - 1] == '\n') {
1733
+ buffer_append_indent(buf);
1734
+ } else if (st[sp].close_brk) {
1735
+ buffer_append_newline(buf);
1736
+ buffer_append_indent(buf);
1737
+ }
1703
1738
  } else if (buf->indent_spaces > 0 && !st[sp].mixed) {
1704
1739
  buffer_append_indent(buf);
1705
1740
  }
@@ -1891,6 +1926,9 @@ LEPTRIS_API char* leptris_document_serialize_ext_sized(
1891
1926
  if (ext_size >= offsetof(LeptrisSerializeExtOptions, html_method) +
1892
1927
  sizeof(int))
1893
1928
  internal.html_method = ext->html_method;
1929
+ if (ext_size >= offsetof(LeptrisSerializeExtOptions, indent_html) +
1930
+ sizeof(int))
1931
+ internal.indent_html = ext->indent_html;
1894
1932
  }
1895
1933
  return leptris_document_serialize_ex(doc, options, &internal);
1896
1934
  }
@@ -1926,6 +1964,9 @@ LEPTRIS_API char* leptris_element_serialize_ext_sized(
1926
1964
  if (ext_size >= offsetof(LeptrisSerializeExtOptions, html_method) +
1927
1965
  sizeof(int))
1928
1966
  internal.html_method = ext->html_method;
1967
+ if (ext_size >= offsetof(LeptrisSerializeExtOptions, indent_html) +
1968
+ sizeof(int))
1969
+ internal.indent_html = ext->indent_html;
1929
1970
  }
1930
1971
  return leptris_element_serialize_ex(elem, options, &internal);
1931
1972
  }
@@ -1946,6 +1987,7 @@ char* leptris_element_serialize_ex(LeptrisElement elem,
1946
1987
  buf->cdata_names = extended->cdata_elements;
1947
1988
  buf->cdata_count = extended->cdata_element_count;
1948
1989
  buf->html_method = extended->html_method != 0;
1990
+ buf->indent_html = extended->indent_html != 0;
1949
1991
  buf->indent_text = extended->indent_text != 0;
1950
1992
  buf->expand_empty = extended->expand_empty != 0;
1951
1993
  buf->indent_unit = extended->indent_unit;
@@ -2010,6 +2052,7 @@ char* leptris_document_serialize_ex(struct leptris_document* doc,
2010
2052
  * force XML (Nokogiri's to_xml-on-HTML-doc). */
2011
2053
  if (extended->html_method == -1) buf->html_method = 0;
2012
2054
  else if (extended->html_method == 1) buf->html_method = 1;
2055
+ buf->indent_html = extended->indent_html != 0;
2013
2056
  buf->indent_text = extended->indent_text != 0;
2014
2057
  buf->expand_empty = extended->expand_empty != 0;
2015
2058
  buf->indent_unit = extended->indent_unit;
@@ -77,6 +77,9 @@ typedef struct SerializeBuffer {
77
77
  /* §16.2 method="html": newline-per-block-element layout governed
78
78
  * by the HTML element table (html_elem_flags). */
79
79
  int html_method;
80
+ /* #1635: html layout nests with the indent machinery (0 = the
81
+ * §16.2 newline-only shape). */
82
+ int indent_html;
80
83
  /* libxml2 XHTML serialization (xmlsave.c xhtmlNodeDumpOutput
81
84
  * parity): an xml-method result whose doctype ids match an XHTML
82
85
  * DTD injects the Content-Type meta into the root html/head and
@@ -138,6 +141,7 @@ typedef struct {
138
141
  /* Indent unit string (#633): one copy per depth level; NULL =
139
142
  * indent_spaces spaces per level. */
140
143
  const char* indent_unit;
144
+ int indent_html; /* #1635: nested html indent (§16.2 default 0) */
141
145
  } LeptrisSerializeExtended;
142
146
 
143
147
  LEPTRIS_API char* leptris_document_serialize_ext(
@@ -2843,3 +2843,119 @@ TEST(ElementNewWithAttributes, DuplicateNamesReplaceLastWins) {
2843
2843
  EXPECT_STREQ(leptris_element_attribute(e, "id"), "second");
2844
2844
  leptris_document_free(doc);
2845
2845
  }
2846
+
2847
+ /* #1636: appending a node into its own descendant subtree built a
2848
+ * parent cycle; the serializer (every tree walker) then recursed
2849
+ * unbounded and the process died (_chkstk SEGV on Windows through
2850
+ * moxml fragment merges). Reparenting mutators reject the cycle
2851
+ * edge now. */
2852
+ TEST(DomCycleGuard, AncestorAppendRejected) {
2853
+ LeptrisStatus st = LEPTRIS_OK;
2854
+ LeptrisDocument d =
2855
+ leptris_parse_string("<a><b/></a>", strlen("<a><b/></a>"), &st);
2856
+ ASSERT_NE(d, nullptr);
2857
+ LeptrisElement a = leptris_document_root(d);
2858
+ LeptrisElement b = leptris_element_first_child_any(a);
2859
+ ASSERT_NE(b, nullptr);
2860
+ EXPECT_EQ(leptris_element_append_child(b, a),
2861
+ LEPTRIS_ERROR_INVALID_ARG);
2862
+ EXPECT_EQ(leptris_element_prepend_child(b, a),
2863
+ LEPTRIS_ERROR_INVALID_ARG);
2864
+ EXPECT_EQ(leptris_element_append_child(a, a),
2865
+ LEPTRIS_ERROR_INVALID_ARG);
2866
+ /* the legal shape still works and serializes */
2867
+ LeptrisElement c = leptris_element_create(d, "c");
2868
+ ASSERT_NE(c, nullptr);
2869
+ EXPECT_EQ(leptris_element_append_child(b, c), LEPTRIS_OK);
2870
+ char* out = leptris_document_serialize(d, nullptr);
2871
+ ASSERT_NE(out, nullptr);
2872
+ EXPECT_NE(strstr(out, "<b><c/></b>"), nullptr);
2873
+ leptris_free_string(out);
2874
+ leptris_document_free(d);
2875
+ }
2876
+
2877
+ TEST(DomCycleGuard, InsertIntoOwnSubtreeRejected) {
2878
+ LeptrisStatus st = LEPTRIS_OK;
2879
+ LeptrisDocument d =
2880
+ leptris_parse_string("<a><b><x/></b></a>", strlen("<a><b><x/></b></a>"), &st);
2881
+ ASSERT_NE(d, nullptr);
2882
+ LeptrisElement a = leptris_document_root(d);
2883
+ LeptrisElement b = leptris_element_first_child_any(a);
2884
+ LeptrisElement x = leptris_element_first_child_any(b);
2885
+ ASSERT_NE(x, nullptr);
2886
+ /* inserting a (ancestor) inside a's own subtree */
2887
+ EXPECT_EQ(leptris_element_insert_before(x, a),
2888
+ LEPTRIS_ERROR_INVALID_ARG);
2889
+ EXPECT_EQ(leptris_element_insert_after(x, a),
2890
+ LEPTRIS_ERROR_INVALID_ARG);
2891
+ leptris_document_free(d);
2892
+ }
2893
+
2894
+ /* leptris-ruby#1636: add_child_addr is status-only — a foreign
2895
+ * node is adopted by copy and the installed copy's address is
2896
+ * dropped, so callers kept addressing the foreign original, which
2897
+ * dies with its document. The installed twin reports the
2898
+ * effective node: same-document attaches return the argument,
2899
+ * foreign attaches return the copy (which survives the source
2900
+ * document's free). */
2901
+ TEST(DomAttachInstalled, ForeignAttachReportsCopyAddress) {
2902
+ LeptrisStatus st = LEPTRIS_OK;
2903
+ LeptrisDocument frag =
2904
+ leptris_parse_string("<f><item>t</item></f>", strlen("<f><item>t</item></f>"), &st);
2905
+ ASSERT_NE(frag, nullptr);
2906
+ LeptrisDocument target = leptris_parse_string("<doc/>", 6, &st);
2907
+ ASSERT_NE(target, nullptr);
2908
+ LeptrisElement troot = leptris_document_root(target);
2909
+ LeptrisElement froot = leptris_document_root(frag);
2910
+ LeptrisElement item = leptris_element_first_child_any(froot);
2911
+ ASSERT_NE(item, nullptr);
2912
+
2913
+ uintptr_t installed = 0;
2914
+ EXPECT_EQ(leptris_element_add_child_addr_installed(
2915
+ (uintptr_t)troot, (uintptr_t)item, &installed),
2916
+ LEPTRIS_OK);
2917
+ EXPECT_NE(installed, 0u);
2918
+ /* the copy is a different node than the foreign original */
2919
+ EXPECT_NE(installed, (uintptr_t)item);
2920
+
2921
+ /* the source document dies; the installed copy must not dangle */
2922
+ leptris_document_free(frag);
2923
+ char* out = leptris_element_serialize(troot, nullptr);
2924
+ ASSERT_NE(out, nullptr);
2925
+ EXPECT_STREQ(out, "<doc><item>t</item></doc>");
2926
+ leptris_free_string(out);
2927
+ leptris_document_free(target);
2928
+ }
2929
+
2930
+ TEST(DomAttachInstalled, SameDocumentReturnsArgument) {
2931
+ LeptrisStatus st = LEPTRIS_OK;
2932
+ LeptrisDocument d = leptris_parse_string("<r/>", 4, &st);
2933
+ ASSERT_NE(d, nullptr);
2934
+ LeptrisElement root = leptris_document_root(d);
2935
+ LeptrisElement c = leptris_element_create(d, "c");
2936
+ ASSERT_NE(c, nullptr);
2937
+ uintptr_t installed = 0;
2938
+ EXPECT_EQ(leptris_element_add_child_addr_installed(
2939
+ (uintptr_t)root, (uintptr_t)c, &installed),
2940
+ LEPTRIS_OK);
2941
+ EXPECT_EQ(installed, (uintptr_t)c);
2942
+ leptris_document_free(d);
2943
+ }
2944
+
2945
+ TEST(DomAttachInstalled, NullShapeAndStatusContract) {
2946
+ LeptrisStatus st = LEPTRIS_OK;
2947
+ LeptrisDocument d = leptris_parse_string("<r/>", 4, &st);
2948
+ ASSERT_NE(d, nullptr);
2949
+ LeptrisElement root = leptris_document_root(d);
2950
+ LeptrisElement c = leptris_element_create(d, "c");
2951
+ ASSERT_NE(c, nullptr);
2952
+ /* status-only overload */
2953
+ EXPECT_EQ(leptris_element_add_child_addr_installed(
2954
+ (uintptr_t)root, (uintptr_t)c, NULL),
2955
+ LEPTRIS_OK);
2956
+ /* NULL-shaped errors */
2957
+ EXPECT_EQ(leptris_element_add_child_addr_installed(
2958
+ 0, (uintptr_t)c, NULL),
2959
+ LEPTRIS_ERROR_NULL_ARG);
2960
+ leptris_document_free(d);
2961
+ }
@@ -760,6 +760,99 @@ TEST(SerializeOptions, IndentUnitOnTextBearingLeaves) {
760
760
  leptris_document_free(doc);
761
761
  }
762
762
 
763
+ /* Issue #1635: indent_html — the html-method layout nests with
764
+ * the indent machinery (libxml2 htmlNodeDumpFormatOutput format=1):
765
+ * leads before block children and close tags, single-child
766
+ * elements stay inline, raw text verbatim. The §16.2 default
767
+ * (XSLT method="html") stays newline-only. */
768
+ static char* html_force_serialize(LeptrisDocument doc, int indent,
769
+ int indent_html, int ext_bytes) {
770
+ LeptrisSerializeOptions opts = {0};
771
+ opts.indent = indent;
772
+ opts.xml_declaration = 0;
773
+ LeptrisSerializeExtOptions ext = {0};
774
+ ext.html_method = 1;
775
+ ext.indent_html = indent_html;
776
+ return leptris_document_serialize_ext_sized(
777
+ doc, &opts, &ext,
778
+ ext_bytes > 0 ? (size_t)ext_bytes : sizeof(ext));
779
+ }
780
+
781
+ TEST(SerializeOptions, IndentHtmlNestsBlockChildren) {
782
+ const char xml[] = "<html><head><title>T</title></head><body>"
783
+ "<div id=\"a\"><p>x</p><span>y</span></div>"
784
+ "<script>if (a &lt; b) { c(); }</script></body></html>";
785
+ LeptrisStatus st = LEPTRIS_OK;
786
+ LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
787
+ ASSERT_NE(doc, nullptr);
788
+ char* s = html_force_serialize(doc, 2, 1, 0);
789
+ ASSERT_NE(s, nullptr);
790
+ EXPECT_EQ(std::string(s),
791
+ "<html>\n"
792
+ " <head><title>T</title></head>\n"
793
+ " <body>\n"
794
+ " <div id=\"a\">\n"
795
+ " <p>x</p>\n"
796
+ " <span>y</span>\n"
797
+ " </div>\n"
798
+ " <script>if (a < b) { c(); }</script>\n"
799
+ " </body>\n"
800
+ "</html>");
801
+ leptris_free_string(s);
802
+ leptris_document_free(doc);
803
+ }
804
+
805
+ TEST(SerializeOptions, IndentHtmlLegacyStaysNewlineOnly) {
806
+ const char xml[] = "<html><body><div><p>one</p><p>two</p></div>"
807
+ "</body></html>";
808
+ LeptrisStatus st = LEPTRIS_OK;
809
+ LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
810
+ ASSERT_NE(doc, nullptr);
811
+ char* s = html_force_serialize(doc, 2, 0, 0);
812
+ ASSERT_NE(s, nullptr);
813
+ /* §16.2 byte shape: site-rule newlines, never a space lead —
814
+ * single-child wrappers (html>body>div) keep the inline chain,
815
+ * only multi-child blocks break. */
816
+ EXPECT_EQ(std::string(s),
817
+ "<html><body><div>\n"
818
+ "<p>one</p>\n"
819
+ "<p>two</p>\n"
820
+ "</div></body></html>");
821
+ leptris_free_string(s);
822
+ leptris_document_free(doc);
823
+ }
824
+
825
+ TEST(SerializeOptions, IndentHtmlNotReadPastCallerLayout) {
826
+ /* #644 shape: a caller compiled against the pre-#1635 layout
827
+ * covers exactly through html_method (24 bytes) — the appended
828
+ * field stays zeroed and the output keeps the legacy shape. */
829
+ const char xml[] = "<html><body><div><p>x</p></div></body></html>";
830
+ LeptrisStatus st = LEPTRIS_OK;
831
+ LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
832
+ ASSERT_NE(doc, nullptr);
833
+ const size_t legacy_size =
834
+ offsetof(LeptrisSerializeExtOptions, html_method) + sizeof(int);
835
+ unsigned char raw[64];
836
+ memset(raw, 0x5A, sizeof(raw));
837
+ LeptrisSerializeExtOptions* ext = (LeptrisSerializeExtOptions*)raw;
838
+ ext->indent_text = 0;
839
+ ext->indent_unit = nullptr;
840
+ ext->expand_empty = 0;
841
+ ext->html_method = 1;
842
+ LeptrisSerializeOptions opts = {0};
843
+ opts.indent = 2;
844
+ opts.xml_declaration = 0;
845
+ char* s = leptris_document_serialize_ext_sized(
846
+ doc, &opts, ext, legacy_size);
847
+ ASSERT_NE(s, nullptr);
848
+ char* want = html_force_serialize(doc, 2, 0, 0);
849
+ ASSERT_NE(want, nullptr);
850
+ EXPECT_EQ(std::string(s), std::string(want));
851
+ leptris_free_string(s);
852
+ leptris_free_string(want);
853
+ leptris_document_free(doc);
854
+ }
855
+
763
856
  /* Issue #644: FFI callers allocate only the fields they know — the
764
857
  * sized entry must not read past their buffer. The Ruby binding's
765
858
  * layout is exactly one int (indent_text): a 4-byte ext with garbage
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
3
3
  "name": "leptris",
4
- "version": "1.9.337",
4
+ "version": "1.9.340",
5
5
  "description": "High-performance XML parser and XPath 1.0 engine in C (libleptris)",
6
6
  "homepage": "https://github.com/leptris/leptris",
7
7
  "license": "MIT",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leptris
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.337.0
4
+ version: 1.9.340.0
5
5
  platform: arm-linux
6
6
  authors:
7
7
  - Ribose Inc.