moxml 0.5.121 → 0.5.123

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: 3e70385e5a2ffc34bc69d65011c6fead0dfdb3311ac44d68893990b714aa750b
4
- data.tar.gz: 1d7d88feac80fdef1a56a5e09d333ee350bd9e2cc19c42a26e57a5283e8ab8ef
3
+ metadata.gz: aba5868bf7db2136823ceac2c98f825cad89b1c8f7b8e34d9ac1de2c7cbe1e61
4
+ data.tar.gz: 3b8cdeb8e497d73d0c2d7db37c5f3af95e5a7bc165a6cbad8a68bb2b3cec2913
5
5
  SHA512:
6
- metadata.gz: 846a93feb34b6de7dab678e91b72cfe8691b17fab1987605906919225ce406204b4beb2dbae3d8e95b54bdf42f1ec9895598c22e49d3816d866241f5cb6e0fad
7
- data.tar.gz: 915721b24c27eef6790fa31f22f82dd1f6b3d2998b9c5824c4515a50f4d0500ff2bd40874b414f8a02dce433d90455eda067dd07f35ad127df46182dac8133a1
6
+ metadata.gz: 92aabda5d25c00d5c2d81fa3103ad4580f1e6774827057541659000cb3344e1e056cd922d4ce96a04975d6c29692fa087948a31c41de7d60cd5227f77aff382b
7
+ data.tar.gz: 28cfbef33282d28a6eb0f94c248cbf36399cb8911430b468f9c67f890e2be684d8926d2670c346f54ab7aad9cfb0085f87bfc09dbeb9fed83c8b029e79997134
@@ -279,14 +279,17 @@ module Moxml
279
279
 
280
280
  def xsd_validate(xsd_handle, native_document)
281
281
  # +xsd_handle+ is the binding's Leptris::XML::XSD::Schema;
282
- # validate_errors takes the binding document and returns
283
- # the engine's accumulated messages ([] = valid).
282
+ # validate_errors takes the binding document. Entries
283
+ # normalize to Strings: the moxml contract is []-of-
284
+ # messages, and the binding may enrich entries into
285
+ # structured objects (element/line/column —
286
+ # leptris-ruby#419) without breaking consumers.
284
287
  doc = if native_document.is_a?(::Leptris::XML::Document)
285
288
  native_document
286
289
  else
287
290
  to_binding(native_document)
288
291
  end
289
- xsd_handle.validate_errors(doc)
292
+ xsd_handle.validate_errors(doc).map(&:to_s)
290
293
  end
291
294
 
292
295
  def builder_face(native_document)
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.121"
4
+ VERSION = "0.5.123"
5
5
  end
data/lib/moxml/xsd.rb CHANGED
@@ -57,11 +57,29 @@ module Moxml
57
57
  end
58
58
 
59
59
  # Validate a node or raw XML string. Returns [] when valid.
60
+ # FROZEN string sources parse once and are memoized for the
61
+ # schema's lifetime — re-validating the same document is the
62
+ # hot consumer shape, and a per-call parse costs the full
63
+ # document pool every time (moxml#350's MB-per-validate
64
+ # growth). Unfrozen strings re-parse (mutation must be
65
+ # visible); pass a Moxml::Document to control the parse
66
+ # yourself.
60
67
  def validate(node_or_xml)
61
68
  doc = case node_or_xml
62
69
  when Moxml::Document then node_or_xml
63
70
  when Moxml::Node then node_or_xml.document
64
- else @context.parse(node_or_xml.to_s)
71
+ else
72
+ cached = @parsed_source
73
+ if cached && node_or_xml.frozen? &&
74
+ cached[0].equal?(node_or_xml)
75
+ cached[1]
76
+ else
77
+ parsed = @context.parse(node_or_xml.to_s)
78
+ if node_or_xml.frozen?
79
+ @parsed_source = [node_or_xml, parsed]
80
+ end
81
+ parsed
82
+ end
65
83
  end
66
84
  @context.config.adapter.xsd_validate(@handle, doc.native)
67
85
  end
@@ -101,6 +101,35 @@ RSpec.describe Moxml::XSD do
101
101
  end
102
102
  end
103
103
 
104
+ it "memoizes the parse for frozen string sources (moxml#350)" do
105
+ schema = ctx.xsd(schema_text)
106
+ source = "<note><to>You</to></note>"
107
+ first = schema.validate(source)
108
+ parsed = schema.instance_variable_get(:@parsed_source)
109
+ expect(parsed[0]).to equal(source)
110
+ 3.times { schema.validate(source) }
111
+ # same source object, one parse — the memo entry is untouched
112
+ expect(schema.instance_variable_get(:@parsed_source)[1])
113
+ .to equal(parsed[1])
114
+ expect(first).to eq([])
115
+ end
116
+
117
+ it "re-parses unfrozen string sources (mutation stays visible)" do
118
+ schema = ctx.xsd(schema_text)
119
+ mutable = +"<note><to>You</to></note>"
120
+ expect(schema.valid?(mutable)).to be(true)
121
+ mutable.replace("<note><wrong/></note>")
122
+ expect(schema.valid?(mutable)).to be(false)
123
+ expect(schema.instance_variable_get(:@parsed_source)).to be_nil
124
+ end
125
+
126
+ it "normalizes validate entries to strings (moxml contract)" do
127
+ schema = ctx.xsd(schema_text)
128
+ errors = schema.validate("<note><wrong/></note>")
129
+ expect(errors).not_to be_empty
130
+ expect(errors).to all(be_a(String))
131
+ end
132
+
104
133
  it "derives XSD_SUPPORTED from the engine face gate" do
105
134
  # The capability flag must not outrun the engine faces: a
106
135
  # misreleased lockstep (NATIVE_PLAN_STRUCTS lesson) would arm
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.121
4
+ version: 0.5.123
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-10-10 00:00:00.000000000 Z
11
+ date: 2026-10-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Moxml is a unified XML manipulation library that provides a common API