nokogiri 1.6.7.2 → 1.6.8.rc1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +12 -9
- data/CHANGELOG.ja.rdoc +18 -0
- data/CHANGELOG.rdoc +12 -7
- data/CONTRIBUTING.md +42 -0
- data/Gemfile +1 -1
- data/Manifest.txt +6 -0
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/bin/nokogiri +2 -2
- data/dependencies.yml +1 -1
- data/ext/nokogiri/extconf.rb +3 -3
- data/ext/nokogiri/nokogiri.c +0 -7
- data/ext/nokogiri/nokogiri.h +1 -34
- data/ext/nokogiri/xml_document.c +2 -4
- data/ext/nokogiri/xml_namespace.c +56 -17
- data/ext/nokogiri/xml_node.c +12 -36
- data/ext/nokogiri/xml_node_set.c +169 -143
- data/ext/nokogiri/xml_node_set.h +3 -4
- data/ext/nokogiri/xml_sax_parser.c +2 -5
- data/ext/nokogiri/xml_syntax_error.c +0 -4
- data/ext/nokogiri/xml_syntax_error.h +0 -1
- data/ext/nokogiri/xml_xpath_context.c +9 -18
- data/lib/nokogiri.rb +3 -0
- data/lib/nokogiri/css/parser.rb +8 -2
- data/lib/nokogiri/css/parser.y +7 -2
- data/lib/nokogiri/version.rb +1 -1
- data/lib/nokogiri/xml/document.rb +7 -1
- data/lib/nokogiri/xml/dtd.rb +4 -4
- data/lib/nokogiri/xml/node.rb +2 -2
- data/ports/archives/libxml2-2.9.3.tar.gz +0 -0
- data/test/css/test_parser.rb +7 -1
- data/test/files/GH_1042.html +18 -0
- data/test/files/namespace_pressure_test.xml +1684 -0
- data/test/files/tlm.html +2 -1
- data/test/html/sax/test_parser.rb +2 -2
- data/test/html/test_document.rb +18 -8
- data/test/html/test_document_encoding.rb +46 -54
- data/test/html/test_document_fragment.rb +21 -22
- data/test/html/test_node.rb +16 -0
- data/test/html/test_node_encoding.rb +12 -14
- data/test/namespaces/test_namespaces_in_parsed_doc.rb +14 -0
- data/test/test_reader.rb +19 -0
- data/test/test_xslt_transforms.rb +5 -3
- data/test/xml/sax/test_parser.rb +36 -39
- data/test/xml/test_document.rb +7 -2
- data/test/xml/test_document_encoding.rb +14 -16
- data/test/xml/test_dtd_encoding.rb +0 -2
- data/test/xml/test_node_encoding.rb +78 -80
- data/test/xml/test_reader_encoding.rb +100 -102
- data/test/xslt/test_exception_handling.rb +1 -1
- metadata +11 -28
- data/patches/libxml2/0001-Revert-Missing-initialization-for-the-catalog-module.patch +0 -29
- data/patches/libxml2/0002-Fix-missing-entities-after-CVE-2014-3660-fix.patch +0 -31
- data/patches/libxml2/0003-Stop-parsing-on-entities-boundaries-errors.patch +0 -32
- data/patches/libxml2/0004-Cleanup-conditional-section-error-handling.patch +0 -49
- data/patches/libxml2/0005-CVE-2015-1819-Enforce-the-reader-to-run-in-constant-.patch +0 -177
- data/patches/libxml2/0006-Another-variation-of-overflow-in-Conditional-section.patch +0 -32
- data/patches/libxml2/0007-Fix-an-error-in-previous-Conditional-section-patch.patch +0 -28
- data/patches/libxml2/0008-CVE-2015-8035-Fix-XZ-compression-support-loop.patch +0 -31
- data/patches/libxml2/0009-Updated-config.guess.patch +0 -397
- data/patches/libxml2/0010-Fix-parsering-short-unclosed-comment-uninitialized-access.patch +0 -64
- data/patches/libxml2/0011-Avoid-extra-processing-of-MarkupDecl-when-EOF.patch +0 -35
- data/patches/libxml2/0012-Avoid-processing-entities-after-encoding-conversion-.patch +0 -83
- data/patches/libxml2/0013-CVE-2015-7497-Avoid-an-heap-buffer-overflow-in-xmlDi.patch +0 -33
- data/patches/libxml2/0014-CVE-2015-5312-Another-entity-expansion-issue.patch +0 -32
- data/patches/libxml2/0015-Add-xmlHaltParser-to-stop-the-parser.patch +0 -81
- data/patches/libxml2/0016-Detect-incoherency-on-GROW.patch +0 -36
- data/patches/libxml2/0017-CVE-2015-7500-Fix-memory-access-error-due-to-incorre.patch +0 -105
- data/patches/libxml2/0018-CVE-2015-8242-Buffer-overead-with-HTML-parser-in-pus.patch +0 -43
- data/patches/libxml2/0019-Do-not-print-error-context-when-there-is-none.patch +0 -28
- data/patches/libxml2/0020-xmlStopParser-reset-errNo.patch +0 -41
- data/patches/libxml2/0021-Reuse-xmlHaltParser-where-it-makes-sense.patch +0 -175
- data/ports/archives/libxml2-2.9.2.tar.gz +0 -0
data/test/xml/test_document.rb
CHANGED
@@ -28,8 +28,13 @@ module Nokogiri
|
|
28
28
|
|
29
29
|
# issue #1005
|
30
30
|
def test_strict_parsing_empty_doc_should_raise_exception
|
31
|
-
|
32
|
-
|
31
|
+
["", " "].each do |empty_string|
|
32
|
+
assert_raises(SyntaxError, "empty string '#{empty_string}' should raise a SyntaxError") do
|
33
|
+
Nokogiri::XML(empty_string) { |c| c.strict }
|
34
|
+
end
|
35
|
+
assert_raises(SyntaxError, "StringIO of '#{empty_string}' should raise a SyntaxError") do
|
36
|
+
Nokogiri::XML(StringIO.new(empty_string)) { |c| c.strict }
|
37
|
+
end
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
@@ -2,25 +2,23 @@ require "helper"
|
|
2
2
|
|
3
3
|
module Nokogiri
|
4
4
|
module XML
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
5
|
+
class TestDocumentEncoding < Nokogiri::TestCase
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE, 'UTF-8')
|
9
|
+
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def test_url
|
12
|
+
assert_equal @xml.encoding, @xml.url.encoding.name
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
def test_encoding
|
16
|
+
assert_equal @xml.encoding, @xml.encoding.encoding.name
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
19
|
+
def test_dotted_version
|
20
|
+
if Nokogiri.uses_libxml?
|
21
|
+
assert_equal 'UTF-8', Nokogiri::LIBXML_VERSION.encoding.name
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
@@ -2,104 +2,102 @@ require "helper"
|
|
2
2
|
|
3
3
|
module Nokogiri
|
4
4
|
module XML
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
5
|
+
class TestNodeEncoding < Nokogiri::TestCase
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@html = Nokogiri::HTML(File.read(HTML_FILE), HTML_FILE)
|
9
|
+
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
def test_get_attribute
|
12
|
+
node = @html.css('a').first
|
13
|
+
assert_equal @html.encoding, node['href'].encoding.name
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
def test_text_encoding_is_utf_8
|
17
|
+
@html = Nokogiri::HTML(File.open(NICH_FILE))
|
18
|
+
assert_equal 'UTF-8', @html.text.encoding.name
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
def test_serialize_encoding_html
|
22
|
+
@html = Nokogiri::HTML(File.open(NICH_FILE))
|
23
|
+
assert_equal @html.encoding.downcase,
|
24
|
+
@html.serialize.encoding.name.downcase
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
@doc = Nokogiri::HTML(@html.serialize)
|
27
|
+
assert_equal @html.serialize, @doc.serialize
|
28
|
+
end
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
def test_serialize_encoding_xml
|
31
|
+
@xml = Nokogiri::XML(File.open(SHIFT_JIS_XML))
|
32
|
+
assert_equal @xml.encoding.downcase,
|
33
|
+
@xml.serialize.encoding.name.downcase
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
@doc = Nokogiri::XML(@xml.serialize)
|
36
|
+
assert_equal @xml.serialize, @doc.serialize
|
37
|
+
end
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
def test_encode_special_chars
|
40
|
+
foo = @html.css('a').first.encode_special_chars('foo')
|
41
|
+
assert_equal @html.encoding, foo.encoding.name
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
def test_content
|
45
|
+
node = @html.css('a').first
|
46
|
+
assert_equal @html.encoding, node.content.encoding.name
|
47
|
+
end
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
def test_name
|
50
|
+
node = @html.css('a').first
|
51
|
+
assert_equal @html.encoding, node.name.encoding.name
|
52
|
+
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
def test_path
|
55
|
+
node = @html.css('a').first
|
56
|
+
assert_equal @html.encoding, node.path.encoding.name
|
57
|
+
end
|
59
58
|
|
60
|
-
|
61
|
-
|
59
|
+
def test_namespace
|
60
|
+
xml = <<-eoxml
|
62
61
|
<root>
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
62
|
+
<car xmlns:part="http://general-motors.com/">
|
63
|
+
<part:tire>Michelin Model XGV</part:tire>
|
64
|
+
</car>
|
65
|
+
<bicycle xmlns:part="http://schwinn.com/">
|
66
|
+
<part:tire>I'm a bicycle tire!</part:tire>
|
67
|
+
</bicycle>
|
69
68
|
</root>
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
69
|
+
eoxml
|
70
|
+
doc = Nokogiri::XML(xml, nil, 'UTF-8')
|
71
|
+
assert_equal 'UTF-8', doc.encoding
|
72
|
+
n = doc.xpath('//part:tire', { 'part' => 'http://schwinn.com/' }).first
|
73
|
+
assert n
|
74
|
+
assert_equal doc.encoding, n.namespace.href.encoding.name
|
75
|
+
assert_equal doc.encoding, n.namespace.prefix.encoding.name
|
76
|
+
end
|
78
77
|
|
79
|
-
|
80
|
-
|
78
|
+
def test_namespace_as_hash
|
79
|
+
xml = <<-eoxml
|
81
80
|
<root>
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
81
|
+
<car xmlns:part="http://general-motors.com/">
|
82
|
+
<part:tire>Michelin Model XGV</part:tire>
|
83
|
+
</car>
|
84
|
+
<bicycle xmlns:part="http://schwinn.com/">
|
85
|
+
<part:tire>I'm a bicycle tire!</part:tire>
|
86
|
+
</bicycle>
|
88
87
|
</root>
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
88
|
+
eoxml
|
89
|
+
doc = Nokogiri::XML(xml, nil, 'UTF-8')
|
90
|
+
assert_equal 'UTF-8', doc.encoding
|
91
|
+
assert n = doc.xpath('//car').first
|
93
92
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
93
|
+
n.namespace_definitions.each do |nd|
|
94
|
+
assert_equal doc.encoding, nd.href.encoding.name
|
95
|
+
assert_equal doc.encoding, nd.prefix.encoding.name
|
96
|
+
end
|
98
97
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
98
|
+
n.namespaces.each do |k,v|
|
99
|
+
assert_equal doc.encoding, k.encoding.name
|
100
|
+
assert_equal doc.encoding, v.encoding.name
|
103
101
|
end
|
104
102
|
end
|
105
103
|
end
|
@@ -3,131 +3,129 @@ require "helper"
|
|
3
3
|
|
4
4
|
module Nokogiri
|
5
5
|
module XML
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
6
|
+
class TestReaderEncoding < Nokogiri::TestCase
|
7
|
+
def setup
|
8
|
+
super
|
9
|
+
@reader = Nokogiri::XML::Reader(
|
10
|
+
File.read(XML_FILE),
|
11
|
+
XML_FILE,
|
12
|
+
'UTF-8'
|
13
|
+
)
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
16
|
+
def test_attribute_at
|
17
|
+
@reader.each do |node|
|
18
|
+
next unless attribute = node.attribute_at(0)
|
19
|
+
assert_equal @reader.encoding, attribute.encoding.name
|
22
20
|
end
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
23
|
+
def test_attributes
|
24
|
+
@reader.each do |node|
|
25
|
+
node.attributes.each do |k,v|
|
26
|
+
assert_equal @reader.encoding, k.encoding.name
|
27
|
+
assert_equal @reader.encoding, v.encoding.name
|
30
28
|
end
|
31
29
|
end
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
32
|
+
def test_attribute
|
33
|
+
xml = <<-eoxml
|
34
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
35
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
36
|
+
</x>
|
37
|
+
eoxml
|
38
|
+
reader = Nokogiri::XML::Reader(xml, nil, 'UTF-8')
|
39
|
+
reader.each do |node|
|
40
|
+
next unless attribute = node.attribute('awesome')
|
41
|
+
assert_equal reader.encoding, attribute.encoding.name
|
44
42
|
end
|
43
|
+
end
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
45
|
+
def test_xml_version
|
46
|
+
@reader.each do |node|
|
47
|
+
next unless version = node.xml_version
|
48
|
+
assert_equal @reader.encoding, version.encoding.name
|
51
49
|
end
|
50
|
+
end
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
def test_lang
|
53
|
+
xml = <<-eoxml
|
54
|
+
<awesome>
|
55
|
+
<p xml:lang="en">The quick brown fox jumps over the lazy dog.</p>
|
56
|
+
<p xml:lang="ja">日本語が上手です</p>
|
57
|
+
</awesome>
|
58
|
+
eoxml
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
60
|
+
reader = Nokogiri::XML::Reader(xml, nil, 'UTF-8')
|
61
|
+
reader.each do |node|
|
62
|
+
next unless lang = node.lang
|
63
|
+
assert_equal reader.encoding, lang.encoding.name
|
66
64
|
end
|
65
|
+
end
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
assert called
|
67
|
+
def test_value
|
68
|
+
called = false
|
69
|
+
@reader.each do |node|
|
70
|
+
next unless value = node.value
|
71
|
+
assert_equal @reader.encoding, value.encoding.name
|
72
|
+
called = true
|
76
73
|
end
|
74
|
+
assert called
|
75
|
+
end
|
77
76
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
77
|
+
def test_prefix
|
78
|
+
xml = <<-eoxml
|
79
|
+
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
80
|
+
<edi:foo>hello</edi:foo>
|
81
|
+
</x>
|
82
|
+
eoxml
|
83
|
+
reader = Nokogiri::XML::Reader(xml, nil, 'UTF-8')
|
84
|
+
reader.each do |node|
|
85
|
+
next unless prefix = node.prefix
|
86
|
+
assert_equal reader.encoding, prefix.encoding.name
|
89
87
|
end
|
88
|
+
end
|
90
89
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
90
|
+
def test_ns_uri
|
91
|
+
xml = <<-eoxml
|
92
|
+
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
93
|
+
<edi:foo>hello</edi:foo>
|
94
|
+
</x>
|
95
|
+
eoxml
|
96
|
+
reader = Nokogiri::XML::Reader(xml, nil, 'UTF-8')
|
97
|
+
reader.each do |node|
|
98
|
+
next unless uri = node.namespace_uri
|
99
|
+
assert_equal reader.encoding, uri.encoding.name
|
102
100
|
end
|
101
|
+
end
|
103
102
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
end
|
103
|
+
def test_local_name
|
104
|
+
xml = <<-eoxml
|
105
|
+
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
106
|
+
<edi:foo>hello</edi:foo>
|
107
|
+
</x>
|
108
|
+
eoxml
|
109
|
+
reader = Nokogiri::XML::Reader(xml, nil, 'UTF-8')
|
110
|
+
reader.each do |node|
|
111
|
+
next unless lname = node.local_name
|
112
|
+
assert_equal reader.encoding, lname.encoding.name
|
115
113
|
end
|
114
|
+
end
|
116
115
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
end
|
116
|
+
def test_name
|
117
|
+
@reader.each do |node|
|
118
|
+
next unless name = node.name
|
119
|
+
assert_equal @reader.encoding, name.encoding.name
|
122
120
|
end
|
121
|
+
end
|
123
122
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
end
|
123
|
+
def test_value_lookup_segfault
|
124
|
+
skip("JRuby doesn't do GC.") if Nokogiri.jruby?
|
125
|
+
stress_memory_while do
|
126
|
+
while node = @reader.read
|
127
|
+
nodes = node.send(:attr_nodes)
|
128
|
+
nodes.first.name if nodes.first
|
131
129
|
end
|
132
130
|
end
|
133
131
|
end
|