moxml 0.5.121 → 0.5.122
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 +4 -4
- data/lib/moxml/version.rb +1 -1
- data/lib/moxml/xsd.rb +19 -1
- data/spec/moxml/xsd_spec.rb +22 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5366b1e4d4b177747964da2c010c7b45a93fd31d71b0ec06b531c87fcee8fd95
|
|
4
|
+
data.tar.gz: d7bd6f17cadea96f07c861dcd753201076e9f5b98c7f60c9ac8d965bdfe6cbfc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0980aadf7e42a333fa96984c945b7b2b4954ca7fefa32972e5ac29dd85a27b1334a461b88f278769a70776e7207f684848e588735d47ddb66420a5781fd1542a'
|
|
7
|
+
data.tar.gz: 51a9461b90b4df2b5a56c47f68f35f6eaf4338822bb153c9ec5d53db05b390540e16f516f5bcc72c30dc376297551f8d3e0e1f623d4464f93ac821cf7c8b6048
|
data/lib/moxml/version.rb
CHANGED
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
|
|
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
|
data/spec/moxml/xsd_spec.rb
CHANGED
|
@@ -101,6 +101,28 @@ 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
|
+
|
|
104
126
|
it "derives XSD_SUPPORTED from the engine face gate" do
|
|
105
127
|
# The capability flag must not outrun the engine faces: a
|
|
106
128
|
# 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.
|
|
4
|
+
version: 0.5.122
|
|
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-
|
|
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
|