moxml 0.5.82 → 0.5.84
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ff836e409dd2cf77368c7b26015e57de1b0af5e0678489e6e10452a6c70cc61a
|
|
4
|
+
data.tar.gz: a2a09b561505f90fc624089e925c3b41d4ab867668b00fd35f1132787e9dbfde
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: decb847bc6cfd50e816c916d98c74b837d63e9e38a9b49a2d964333a141a8fafd9e55291f83a52739403ad99126884c2a37928567ac9f4f8fdaae3ca9df37692
|
|
7
|
+
data.tar.gz: 59be5497f4f1a4d439e86b4138be240b1bcabb370bc6d991d79b92aa64e9a40f0243b29f090d4171fd45146593ed27fc2da29ae2a2a72d0f542919e3e5aecf3b
|
|
@@ -30,6 +30,7 @@ module Moxml
|
|
|
30
30
|
::Nokogiri::XML::DocumentFragment.parse(processed) do |config|
|
|
31
31
|
config.strict.nonet
|
|
32
32
|
config.recover
|
|
33
|
+
config.huge
|
|
33
34
|
end.children.to_a
|
|
34
35
|
end
|
|
35
36
|
|
|
@@ -64,12 +65,18 @@ module Moxml
|
|
|
64
65
|
config.strict.nonet
|
|
65
66
|
config.recover unless options[:strict]
|
|
66
67
|
config.noblanks if options[:noblanks]
|
|
68
|
+
config.huge
|
|
67
69
|
end
|
|
68
70
|
else
|
|
69
71
|
::Nokogiri::XML(processed_xml, nil, "UTF-8") do |config|
|
|
70
72
|
config.strict.nonet
|
|
71
73
|
config.recover unless options[:strict]
|
|
72
74
|
config.noblanks if options[:noblanks]
|
|
75
|
+
# XML_PARSE_HUGE: lifts libxml2's arbitrary limits —
|
|
76
|
+
# text nodes > 10MB are silently TRUNCATED at 10MB in
|
|
77
|
+
# recover mode, so large documents lose data without
|
|
78
|
+
# it (users parse >10MB XML).
|
|
79
|
+
config.huge
|
|
73
80
|
end
|
|
74
81
|
end
|
|
75
82
|
rescue ::Nokogiri::XML::SyntaxError => e
|
|
@@ -89,7 +96,7 @@ module Moxml
|
|
|
89
96
|
# malformed input never raises.
|
|
90
97
|
def parse_html(html, _options = {}, _context = nil)
|
|
91
98
|
html_string = html.is_a?(IO) || html.is_a?(StringIO) ? html.read : html.to_s
|
|
92
|
-
native_doc = ::Nokogiri::HTML(html_string)
|
|
99
|
+
native_doc = ::Nokogiri::HTML(html_string, &:huge)
|
|
93
100
|
Wrappers::Document.new(native_doc, _context || Context.new(:nokogiri))
|
|
94
101
|
end
|
|
95
102
|
|
data/lib/moxml/version.rb
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# Duplicate attributes are a fatal XML 1.0 §3.1 error (moxml#281,
|
|
6
|
+
# issue #130 banner semantics): the SAX lane must surface them via
|
|
7
|
+
# on_error exactly like the DOM lane's parse_diagnostics. On
|
|
8
|
+
# bindings whose drain claims dup-containing documents (engine <
|
|
9
|
+
# 1.9.242 — leptris#1374), the drain swallows the error; those
|
|
10
|
+
# bindings skip this spec until the ride lands.
|
|
11
|
+
module SaxDupAttrHandlers
|
|
12
|
+
class ErrorCollector < Moxml::SAX::Handler
|
|
13
|
+
attr_reader :errors, :elements
|
|
14
|
+
|
|
15
|
+
def initialize
|
|
16
|
+
super
|
|
17
|
+
@errors = []
|
|
18
|
+
@elements = 0
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def on_error(error)
|
|
22
|
+
@errors << error.message
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def on_start_element(_name, _attrs = {}, _namespaces = {})
|
|
26
|
+
@elements += 1
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
RSpec.describe "SAX duplicate-attribute error surfacing" do
|
|
32
|
+
let(:context) { Moxml.new(:leptris) }
|
|
33
|
+
let(:dup_xml) do
|
|
34
|
+
'<body lang="en" xml:lang="en" xml:lang="en"><div>x</div></body>'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "surfaces the redefined-attribute error through sax_parse" do
|
|
38
|
+
if defined?(Leptris::XML::SAX::Records) &&
|
|
39
|
+
!Leptris::XML::SAX::Records.open(dup_xml).nil?
|
|
40
|
+
skip "engine < 1.9.242 — the drain claims dup-attr documents " \
|
|
41
|
+
"(leptris#1374)"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
handler = SaxDupAttrHandlers::ErrorCollector.new
|
|
45
|
+
context.sax_parse(dup_xml, handler)
|
|
46
|
+
|
|
47
|
+
expect(handler.errors.join).to include("xml:lang redefined")
|
|
48
|
+
expect(handler.elements).to eq(2)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -36,4 +36,22 @@ RSpec.describe Moxml::Adapter::Nokogiri do
|
|
|
36
36
|
expect(doc.parse_errors).to all(be_a(String))
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
|
+
|
|
40
|
+
# libxml2 truncates text nodes over XML_MAX_TEXT_LENGTH (10MB) —
|
|
41
|
+
# silently in recover mode — unless XML_PARSE_HUGE is set. The
|
|
42
|
+
# adapter always passes huge so large documents keep their data.
|
|
43
|
+
describe "XML_PARSE_HUGE (large documents)" do
|
|
44
|
+
let(:ctx) { Moxml.new(:nokogiri) }
|
|
45
|
+
let(:huge_xml) { "<r>#{'x' * 10_000_001}</r>" }
|
|
46
|
+
|
|
47
|
+
it "keeps text nodes over 10MB intact in recover mode" do
|
|
48
|
+
doc = ctx.parse(huge_xml, strict: false)
|
|
49
|
+
expect(doc.root.children.first.text.length).to eq(10_000_001)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "keeps text nodes over 10MB intact in strict mode" do
|
|
53
|
+
doc = ctx.parse(huge_xml)
|
|
54
|
+
expect(doc.root.children.first.text.length).to eq(10_000_001)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
39
57
|
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.
|
|
4
|
+
version: 0.5.84
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -438,6 +438,7 @@ files:
|
|
|
438
438
|
- spec/moxml/adapter/entity_restoration_spec.rb
|
|
439
439
|
- spec/moxml/adapter/headed_ox_spec.rb
|
|
440
440
|
- spec/moxml/adapter/leptris_doc_parts_spec.rb
|
|
441
|
+
- spec/moxml/adapter/leptris_sax_dup_attr_spec.rb
|
|
441
442
|
- spec/moxml/adapter/leptris_sax_records_spec.rb
|
|
442
443
|
- spec/moxml/adapter/leptris_spec.rb
|
|
443
444
|
- spec/moxml/adapter/libxml_internals_spec.rb
|