moxml 0.5.83 → 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 +4 -4
- data/lib/moxml/adapter/nokogiri.rb +8 -1
- data/lib/moxml/version.rb +1 -1
- data/spec/moxml/adapter/nokogiri_spec.rb +18 -0
- metadata +1 -1
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
|
@@ -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
|