moxml 0.5.112 → 0.5.113

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: 63a1ceed1b65075fbb6187383de91bba6fa8a4dc98d7b6c5e1a8b72c6cdbd5c8
4
- data.tar.gz: f60b17278dd6ce812b27e7bcae595fe464d3192d24bfd68c0b6fb98c285b4dea
3
+ metadata.gz: c61331ea3536aa41170080eb6233643b3b48da707d268da9185ed11fbdcad87d
4
+ data.tar.gz: ef1765b2e2651438c8d38012ea374e2a8b9fe6ebcaff63d2afaf476eb0f727ab
5
5
  SHA512:
6
- metadata.gz: 7a4fd16c91ce73fe9fd1ce72d617fe1d5009d454e5bf8418b1e96f36c804459e4b0186d593b813a84d9092fb9c5818f6b25a95aac6b69feedc34eeba2822ad26
7
- data.tar.gz: 7f1238c394d8ad91e18176ca7d863477ed968fc91bf093a5113885c33665a15a1f83a2696fa68131e039344905679739f97d4c0b1f5ef06b1baf438231ad74c3
6
+ metadata.gz: 2058949ca13a105d38f86b5c38acf3fb974ca9445faedda64ea7d857bf8f10561d5b6df42d7b56ede501d0fcb9186f0347349faee29dd66868b83ec47a94ac4c
7
+ data.tar.gz: c7c7b4f0b0d529ec793e790072d2115fe6ff7c17a389e08a84abadc2ab324e058f4f49d1e5d5a6e1143b0f688ac893b5ebae083638f1482b9b526b99d7c636fd
@@ -1893,6 +1893,44 @@ module Moxml
1893
1893
  installed
1894
1894
  end
1895
1895
 
1896
+ # moxml#335: the engine's document resolution can mis-report
1897
+ # pool ownership under spec-order state (the #1242 TLS-memo
1898
+ # family), so a plain add can -1 for ANY node kind — not just
1899
+ # elements and text. Elements rebuild structurally (the #376
1900
+ # contract); every other kind carries no cross-document
1901
+ # identity worth preserving, so reconstruct it in the parent's
1902
+ # document through the binding's create faces.
1903
+ def rebuild_foreign_child(parent_nn, child_nn)
1904
+ doc = NN_DOCUMENT.bind_call(parent_nn)
1905
+ rebuilt =
1906
+ case child_nn.node_type
1907
+ when :element
1908
+ return structural_adopt(parent_nn, child_nn)
1909
+ when :text
1910
+ doc.create_text_node(child_nn.text)
1911
+ when :comment
1912
+ doc.create_comment(child_nn.text)
1913
+ when :cdata
1914
+ doc.create_cdata(child_nn.text)
1915
+ when :processing_instruction, :pi
1916
+ doc.create_processing_instruction(
1917
+ child_nn.target, child_nn.content.to_s
1918
+ )
1919
+ else
1920
+ raise Moxml::DocumentStructureError.new(
1921
+ "cannot rebuild a #{child_nn.node_type} node",
1922
+ )
1923
+ end
1924
+ # The raw engine add rejects binding-family children —
1925
+ # append through the FFI face like structural_adopt.
1926
+ ::Leptris::XML::FFI.check_status(
1927
+ ::Leptris::XML::FFI.leptris_element_append_child(
1928
+ ::FFI::Pointer.new(parent_nn.address), rebuilt.c_ptr
1929
+ ),
1930
+ )
1931
+ rebuilt
1932
+ end
1933
+
1896
1934
  def copy_binding_subtree(doc, src)
1897
1935
  sub = doc.create_element(src.name.to_s)
1898
1936
  (src.respond_to?(:attributes) ? src.attributes : {}).each do |k, v|
@@ -2107,24 +2145,15 @@ module Moxml
2107
2145
  child = doc.create_text_node(child) if child.is_a?(String)
2108
2146
  # The engine's document resolution can mis-report pool
2109
2147
  # ownership under spec-order state (the #1242 TLS-memo
2110
- # family) — an -1 rejection falls back to the structural
2111
- # adopt for elements rather than raising through the flow.
2148
+ # family) — an -1 rejection rebuilds the child in the
2149
+ # parent's document for every reconstructible kind
2150
+ # (moxml#335), rather than raising through the flow.
2112
2151
  begin
2113
2152
  return NN_ADD_CHILD.bind_call(parent, child)
2114
2153
  rescue ::Leptris::XML::Error, ::RuntimeError => e
2115
2154
  raise unless e.message.include?("append_child failed")
2116
- raise unless %i[element text].include?(child.node_type)
2117
2155
 
2118
- if child.node_type == :element
2119
- structural_adopt(parent, child)
2120
- else
2121
- # A text node carries no cross-document identity worth
2122
- # preserving: rebuild it in the parent's document
2123
- NN_ADD_CHILD.bind_call(
2124
- parent,
2125
- doc.create_text_node(child.text),
2126
- )
2127
- end
2156
+ rebuild_foreign_child(parent, child)
2128
2157
  end
2129
2158
  end
2130
2159
 
data/lib/moxml/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Moxml
4
- VERSION = "0.5.112"
4
+ VERSION = "0.5.113"
5
5
  end
@@ -10,6 +10,7 @@ require "spec_helper"
10
10
  # names, doc-owned).
11
11
  RSpec.describe "leptris cross-document adoption" do
12
12
  let(:ctx) { Moxml.new(:leptris) }
13
+ let(:ad) { Moxml::Adapter::Leptris }
13
14
 
14
15
  it "add_child lands the adopted copy in the tree" do
15
16
  doc = ctx.parse("<r><a/></r>")
@@ -100,4 +101,49 @@ RSpec.describe "leptris cross-document adoption" do
100
101
  expect(mid.root.to_xml).not_to include("<deep")
101
102
  end
102
103
  end
104
+
105
+ # moxml#335: the -1 fallback must not re-raise by node kind — the
106
+ # engine's document resolution can mis-report pool ownership for
107
+ # ANY child (the #1242 TLS-memo family), and only elements have a
108
+ # cross-document identity worth a structural rebuild. The helper
109
+ # is specced directly: the engine failure is CI-only, so forcing
110
+ # the -1 locally is not reproducible.
111
+ context "when the add_child -1 rebuild fallback fires" do
112
+ it "rebuilds comments in the parent's document" do
113
+ doc = ctx.parse("<r/>")
114
+ other = ctx.parse("<other><!-- note --></other>")
115
+ ad.rebuild_foreign_child(doc.root.native, other.root.children.first.native)
116
+ expect(doc.root.to_xml).to include("<!-- note -->")
117
+ expect(other.root.to_xml).to include("<!-- note -->")
118
+ end
119
+
120
+ it "rebuilds CDATA in the parent's document" do
121
+ doc = ctx.parse("<r/>")
122
+ other = ctx.parse("<other><![CDATA[x < y]]></other>")
123
+ ad.rebuild_foreign_child(doc.root.native, other.root.children.first.native)
124
+ expect(doc.root.to_xml).to include("<![CDATA[x < y]]>")
125
+ end
126
+
127
+ it "rebuilds processing instructions in the parent's document" do
128
+ doc = ctx.parse("<r/>")
129
+ other = ctx.parse("<other><?tgt data='1'?></other>")
130
+ ad.rebuild_foreign_child(doc.root.native, other.root.children.first.native)
131
+ expect(doc.root.to_xml).to include("<?tgt data='1'?>")
132
+ end
133
+
134
+ it "rebuilds text in the parent's document" do
135
+ doc = ctx.parse("<r/>")
136
+ other = ctx.parse("<other>t</other>")
137
+ ad.rebuild_foreign_child(doc.root.native, other.root.children.first.native)
138
+ expect(doc.root.to_xml).to include(">t<")
139
+ end
140
+
141
+ it "rebuilds elements structurally" do
142
+ doc = ctx.parse("<r/>")
143
+ other = ctx.parse("<other><e k='v'>t</e></other>")
144
+ ad.rebuild_foreign_child(doc.root.native, other.root.children.first.native)
145
+ expect(doc.at("//r/e")["k"]).to eq("v")
146
+ expect(doc.at("//r/e").text).to eq("t")
147
+ end
148
+ end
103
149
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.112
4
+ version: 0.5.113
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.