moxml 0.6.21 → 0.6.23
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/Gemfile +1 -1
- data/README.adoc +1 -1
- data/lib/moxml/adapter/base.rb +6 -0
- data/lib/moxml/adapter/libxml.rb +1 -1
- data/lib/moxml/adapter/nokogiri.rb +1 -1
- data/lib/moxml/adapter/oga.rb +1 -1
- data/lib/moxml/adapter/ox.rb +1 -1
- data/lib/moxml/adapter/rexml.rb +1 -1
- data/lib/moxml/entity.rb +21 -2
- data/lib/moxml/version.rb +1 -1
- data/spec/moxml/preprocess_encoding_spec.rb +54 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fb2d61022821c9c81d11371a5d97ef32040c040039d54428548b7996cf7b63cb
|
|
4
|
+
data.tar.gz: '09b7a98f8e4b9812846ff9db5461c99da69b7f9315cf27c1be85373c6e2d1df6'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d42184c7983090bec857d3295da85372b99a93814999eb53c28f47789d8025f97c37f5d3c26604a8b32c436a03e7541128b0bcbfedf24b929ef0e0d4c040e7d1
|
|
7
|
+
data.tar.gz: '096f216f8e8b14623b195d099e6c6f19583ba053c13bd63a1d66728ea33e65643b7064c17f2b5b955d61f1bccc070eaa09d25b5a2effd1567ae53c31adae224e'
|
data/Gemfile
CHANGED
data/README.adoc
CHANGED
|
@@ -128,7 +128,7 @@ pair serves; cross-import schema sets (`Context#xsd_set`) ride the
|
|
|
128
128
|
compile_set face (1.9.386.0 ✓, the floor now requires it).
|
|
129
129
|
|===
|
|
130
130
|
|
|
131
|
-
NOTE: moxml's dev Gemfile pins `leptris ~> 1.9.
|
|
131
|
+
NOTE: moxml's dev Gemfile pins `leptris ~> 1.9.450` (the tested pair; the gemspec itself has zero runtime dependencies). The adapter enforces the floor at load.
|
|
132
132
|
`ox ~> 2.14`, `libxml-ruby >= 5.0`, and the vendored oga fork — the CI
|
|
133
133
|
matrix tests exactly those floors.
|
|
134
134
|
|
data/lib/moxml/adapter/base.rb
CHANGED
|
@@ -29,6 +29,12 @@ module Moxml
|
|
|
29
29
|
Entity.preprocess_entities(xml)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
# The document-parse-entry variant (#604): adds the
|
|
33
|
+
# declared-encoding rewrite on top of the general path.
|
|
34
|
+
def preprocess_for_parse(xml)
|
|
35
|
+
Entity.preprocess_for_parse(xml)
|
|
36
|
+
end
|
|
37
|
+
|
|
32
38
|
def decode_entities(text)
|
|
33
39
|
Entity.decode_entities(text)
|
|
34
40
|
end
|
data/lib/moxml/adapter/libxml.rb
CHANGED
|
@@ -200,7 +200,7 @@ module Moxml
|
|
|
200
200
|
# Preprocess entities before parsing.
|
|
201
201
|
# This converts the string to UTF-8; LibXML will use the encoding
|
|
202
202
|
# parameter or XML declaration for byte interpretation.
|
|
203
|
-
xml_string =
|
|
203
|
+
xml_string = preprocess_for_parse(xml_string)
|
|
204
204
|
|
|
205
205
|
# Extract DOCTYPE before parsing. Locate the literal first:
|
|
206
206
|
# a plain memscan keeps doctype-less documents (the common
|
|
@@ -32,7 +32,7 @@ module Moxml
|
|
|
32
32
|
# Nokogiri has a real fragment node type — its children ARE
|
|
33
33
|
# the fragment's top-level nodes.
|
|
34
34
|
def parse_fragment(xml, _context = nil)
|
|
35
|
-
processed = Entity.
|
|
35
|
+
processed = Entity.preprocess_for_parse(xml)
|
|
36
36
|
::Nokogiri::XML::DocumentFragment.parse(processed) do |config|
|
|
37
37
|
config.strict.nonet
|
|
38
38
|
config.recover
|
data/lib/moxml/adapter/oga.rb
CHANGED
|
@@ -44,7 +44,7 @@ module Moxml
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def parse(xml, options = {}, _context = nil)
|
|
47
|
-
processed_xml = strip_bom(
|
|
47
|
+
processed_xml = strip_bom(preprocess_for_parse(xml))
|
|
48
48
|
|
|
49
49
|
native_doc = begin
|
|
50
50
|
::Oga.parse_xml(processed_xml, strict: options[:strict])
|
data/lib/moxml/adapter/ox.rb
CHANGED
|
@@ -35,7 +35,7 @@ module Moxml
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def parse(xml, options = {}, _context = nil)
|
|
38
|
-
processed_xml =
|
|
38
|
+
processed_xml = preprocess_for_parse(xml)
|
|
39
39
|
native_doc = begin
|
|
40
40
|
# ::Ox.parse has arity 1 and hardcodes skip: :skip_white;
|
|
41
41
|
# ::Ox.load takes the policy (issue #189). Both knobs flow
|
data/lib/moxml/adapter/rexml.rb
CHANGED
|
@@ -36,7 +36,7 @@ module Moxml
|
|
|
36
36
|
processed_xml = xml.encode("UTF-8")
|
|
37
37
|
|
|
38
38
|
# Preprocess entities to avoid double-escaping on output
|
|
39
|
-
processed_xml =
|
|
39
|
+
processed_xml = preprocess_for_parse(processed_xml)
|
|
40
40
|
|
|
41
41
|
native_doc = begin
|
|
42
42
|
::REXML::Document.new(processed_xml)
|
data/lib/moxml/entity.rb
CHANGED
|
@@ -93,7 +93,13 @@ module Moxml
|
|
|
93
93
|
# whether the result can contain markers: the flag rides the
|
|
94
94
|
# same `&` scan, so callers needing it (leptris parse) avoid a
|
|
95
95
|
# second full-buffer multibyte probe.
|
|
96
|
-
|
|
96
|
+
#
|
|
97
|
+
# rewrite_encoding: the declared-encoding rewrite is a
|
|
98
|
+
# document-parse-entry protection only (#604) - the general
|
|
99
|
+
# path serves text emitters whose payloads legitimately BEGIN
|
|
100
|
+
# with an XML declaration (verbatim data), and rewriting them
|
|
101
|
+
# is a content mutation.
|
|
102
|
+
def preprocess_with_marker_flag(xml, rewrite_encoding: false)
|
|
97
103
|
return ["", false] if xml.nil?
|
|
98
104
|
|
|
99
105
|
str = if xml.encoding == Encoding::BINARY
|
|
@@ -112,7 +118,7 @@ module Moxml
|
|
|
112
118
|
else
|
|
113
119
|
xml.encode("UTF-8")
|
|
114
120
|
end
|
|
115
|
-
str = rewrite_declared_encoding(str)
|
|
121
|
+
str = rewrite_declared_encoding(str) if rewrite_encoding
|
|
116
122
|
# Fast path: no `&` means no entity references to mark — skip
|
|
117
123
|
# the regex scan and string allocation entirely. The vast
|
|
118
124
|
# majority of XML payloads contain no entity references.
|
|
@@ -136,10 +142,23 @@ module Moxml
|
|
|
136
142
|
[processed, marked]
|
|
137
143
|
end
|
|
138
144
|
|
|
145
|
+
# The general path (#604): entity marking + UTF-8 normalization
|
|
146
|
+
# WITHOUT the declared-encoding rewrite - payloads that begin
|
|
147
|
+
# with an XML declaration are verbatim data here (text emitters),
|
|
148
|
+
# not parse payloads.
|
|
139
149
|
def preprocess_entities(xml)
|
|
140
150
|
preprocess_with_marker_flag(xml)[0]
|
|
141
151
|
end
|
|
142
152
|
|
|
153
|
+
# The document-parse-entry path: everything preprocess_entities
|
|
154
|
+
# does, plus the declared-encoding rewrite - moxml feeds engines
|
|
155
|
+
# UTF-8 bytes, so a declaration naming another encoding must be
|
|
156
|
+
# rewritten or the bytes decode twice into mojibake. Only the
|
|
157
|
+
# adapter parse entries call this.
|
|
158
|
+
def preprocess_for_parse(xml)
|
|
159
|
+
preprocess_with_marker_flag(xml, rewrite_encoding: true)[0]
|
|
160
|
+
end
|
|
161
|
+
|
|
143
162
|
# Engines honor the DECLARED encoding and re-decode the bytes they
|
|
144
163
|
# are handed — moxml always feeds UTF-8 (see the normalization
|
|
145
164
|
# above), so a declaration naming another encoding must be
|
data/lib/moxml/version.rb
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# lutaml/moxml#604 + lutaml/lutaml-model#1249: the declared-encoding
|
|
6
|
+
# rewrite is a document-parse-entry protection (moxml feeds engines
|
|
7
|
+
# UTF-8 bytes, so a declaration naming another encoding must be
|
|
8
|
+
# rewritten or the bytes decode twice into mojibake). The general
|
|
9
|
+
# `preprocess_entities` API also serves text emitters - payloads that
|
|
10
|
+
# legitimately BEGIN with an XML declaration (an RFC sourcecode block
|
|
11
|
+
# carrying an example document) are verbatim data, and the rewrite
|
|
12
|
+
# mutated them. The general path keeps the entity marking and drops
|
|
13
|
+
# the rewrite; the rewrite rides the parse-entry variant only.
|
|
14
|
+
RSpec.describe "the preprocess encoding scope (#604)" do
|
|
15
|
+
let(:declared_payload) do
|
|
16
|
+
%(<?xml version="1.0" encoding="utf-8"?>\n<EBMLSchema xmlns="urn:ietf:rfc:8794"/>)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe "the general path (text emitters)" do
|
|
20
|
+
it "preserves a payload's declared encoding verbatim" do
|
|
21
|
+
processed = Moxml.preprocess_entities(declared_payload)
|
|
22
|
+
|
|
23
|
+
expect(processed).to include('encoding="utf-8"')
|
|
24
|
+
expect(processed).not_to include('encoding="UTF-8"?>')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "keeps the entity marking behavior" do
|
|
28
|
+
processed = Moxml.preprocess_entities("<a> </a>")
|
|
29
|
+
|
|
30
|
+
# non-standard entities are MARKED (the marker lifecycle), not
|
|
31
|
+
# passed through
|
|
32
|
+
expect(processed).to include(Moxml::Entity::MARKER)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe "the parse-entry path (engine feeds)" do
|
|
37
|
+
it "still rewrites a foreign declared encoding for the engine" do
|
|
38
|
+
# UTF-8 bytes handed to the engine with a declaration naming
|
|
39
|
+
# iso-8859-1: the rewrite keeps the bytes decoding once
|
|
40
|
+
doc = Moxml.new(:leptris).parse(
|
|
41
|
+
%(<?xml version="1.0" encoding="iso-8859-1"?><a>caf\xc3\xa9</a>),
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
expect(doc.root.text).to eq("café")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "rewrites the declaration on the parsed document's reparsed form" do
|
|
48
|
+
payload = declared_payload
|
|
49
|
+
doc = Moxml.new(:leptris).parse(payload)
|
|
50
|
+
|
|
51
|
+
expect(doc.root.name).to eq("EBMLSchema")
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
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.6.
|
|
4
|
+
version: 0.6.23
|
|
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-11-
|
|
11
|
+
date: 2026-11-28 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
|
|
@@ -584,6 +584,7 @@ files:
|
|
|
584
584
|
- spec/moxml/node_type_map_spec.rb
|
|
585
585
|
- spec/moxml/plan_conformance_spec.rb
|
|
586
586
|
- spec/moxml/plan_spec.rb
|
|
587
|
+
- spec/moxml/preprocess_encoding_spec.rb
|
|
587
588
|
- spec/moxml/processing_instruction_spec.rb
|
|
588
589
|
- spec/moxml/reader_spec.rb
|
|
589
590
|
- spec/moxml/readonly_parse_spec.rb
|