nokogiri 1.0.0 → 1.6.8.1
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 +7 -0
- data/.autotest +26 -0
- data/.cross_rubies +9 -0
- data/.editorconfig +17 -0
- data/.gemtest +0 -0
- data/.travis.yml +51 -0
- data/CHANGELOG.rdoc +1160 -0
- data/CONTRIBUTING.md +42 -0
- data/C_CODING_STYLE.rdoc +33 -0
- data/Gemfile +22 -0
- data/LICENSE.txt +31 -0
- data/Manifest.txt +284 -40
- data/README.md +166 -0
- data/ROADMAP.md +111 -0
- data/Rakefile +310 -199
- data/STANDARD_RESPONSES.md +47 -0
- data/Y_U_NO_GEMSPEC.md +155 -0
- data/appveyor.yml +22 -0
- data/bin/nokogiri +118 -0
- data/build_all +45 -0
- data/dependencies.yml +29 -0
- data/ext/nokogiri/depend +358 -0
- data/ext/nokogiri/extconf.rb +664 -34
- data/ext/nokogiri/html_document.c +120 -33
- data/ext/nokogiri/html_document.h +1 -1
- data/ext/nokogiri/html_element_description.c +279 -0
- data/ext/nokogiri/html_element_description.h +10 -0
- data/ext/nokogiri/html_entity_lookup.c +32 -0
- data/ext/nokogiri/html_entity_lookup.h +8 -0
- data/ext/nokogiri/html_sax_parser_context.c +116 -0
- data/ext/nokogiri/html_sax_parser_context.h +11 -0
- data/ext/nokogiri/html_sax_push_parser.c +87 -0
- data/ext/nokogiri/html_sax_push_parser.h +9 -0
- data/ext/nokogiri/nokogiri.c +145 -0
- data/ext/nokogiri/nokogiri.h +131 -0
- data/ext/nokogiri/xml_attr.c +94 -0
- data/ext/nokogiri/xml_attr.h +9 -0
- data/ext/nokogiri/xml_attribute_decl.c +70 -0
- data/ext/nokogiri/xml_attribute_decl.h +9 -0
- data/ext/nokogiri/xml_cdata.c +23 -19
- data/ext/nokogiri/xml_cdata.h +1 -1
- data/ext/nokogiri/xml_comment.c +69 -0
- data/ext/nokogiri/xml_comment.h +9 -0
- data/ext/nokogiri/xml_document.c +501 -54
- data/ext/nokogiri/xml_document.h +14 -1
- data/ext/nokogiri/xml_document_fragment.c +48 -0
- data/ext/nokogiri/xml_document_fragment.h +10 -0
- data/ext/nokogiri/xml_dtd.c +109 -24
- data/ext/nokogiri/xml_dtd.h +3 -1
- data/ext/nokogiri/xml_element_content.c +123 -0
- data/ext/nokogiri/xml_element_content.h +10 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_element_decl.h +9 -0
- data/ext/nokogiri/xml_encoding_handler.c +79 -0
- data/ext/nokogiri/xml_encoding_handler.h +8 -0
- data/ext/nokogiri/xml_entity_decl.c +110 -0
- data/ext/nokogiri/xml_entity_decl.h +10 -0
- data/ext/nokogiri/xml_entity_reference.c +52 -0
- data/ext/nokogiri/xml_entity_reference.h +9 -0
- data/ext/nokogiri/xml_io.c +60 -0
- data/ext/nokogiri/xml_io.h +11 -0
- data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
- data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
- data/ext/nokogiri/xml_namespace.c +117 -0
- data/ext/nokogiri/xml_namespace.h +13 -0
- data/ext/nokogiri/xml_node.c +1285 -315
- data/ext/nokogiri/xml_node.h +4 -6
- data/ext/nokogiri/xml_node_set.c +415 -54
- data/ext/nokogiri/xml_node_set.h +6 -2
- data/ext/nokogiri/xml_processing_instruction.c +56 -0
- data/ext/nokogiri/xml_processing_instruction.h +9 -0
- data/ext/nokogiri/xml_reader.c +316 -77
- data/ext/nokogiri/xml_reader.h +1 -1
- data/ext/nokogiri/xml_relax_ng.c +161 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +215 -80
- data/ext/nokogiri/xml_sax_parser.h +30 -1
- data/ext/nokogiri/xml_sax_parser_context.c +262 -0
- data/ext/nokogiri/xml_sax_parser_context.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +115 -0
- data/ext/nokogiri/xml_sax_push_parser.h +9 -0
- data/ext/nokogiri/xml_schema.c +205 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.c +45 -175
- data/ext/nokogiri/xml_syntax_error.h +4 -2
- data/ext/nokogiri/xml_text.c +37 -14
- data/ext/nokogiri/xml_text.h +1 -1
- data/ext/nokogiri/xml_xpath_context.c +230 -13
- data/ext/nokogiri/xml_xpath_context.h +2 -1
- data/ext/nokogiri/xslt_stylesheet.c +196 -34
- data/ext/nokogiri/xslt_stylesheet.h +6 -1
- data/lib/nokogiri/css/node.rb +18 -61
- data/lib/nokogiri/css/parser.rb +725 -17
- data/lib/nokogiri/css/parser.y +126 -63
- data/lib/nokogiri/css/parser_extras.rb +91 -0
- data/lib/nokogiri/css/syntax_error.rb +7 -0
- data/lib/nokogiri/css/tokenizer.rb +148 -5
- data/lib/nokogiri/css/tokenizer.rex +31 -39
- data/lib/nokogiri/css/xpath_visitor.rb +109 -51
- data/lib/nokogiri/css.rb +24 -3
- data/lib/nokogiri/decorators/slop.rb +42 -0
- data/lib/nokogiri/html/builder.rb +27 -1
- data/lib/nokogiri/html/document.rb +329 -3
- data/lib/nokogiri/html/document_fragment.rb +39 -0
- data/lib/nokogiri/html/element_description.rb +23 -0
- data/lib/nokogiri/html/element_description_defaults.rb +671 -0
- data/lib/nokogiri/html/entity_lookup.rb +13 -0
- data/lib/nokogiri/html/sax/parser.rb +35 -4
- data/lib/nokogiri/html/sax/parser_context.rb +16 -0
- data/lib/nokogiri/html/sax/push_parser.rb +36 -0
- data/lib/nokogiri/html.rb +18 -76
- data/lib/nokogiri/syntax_error.rb +4 -0
- data/lib/nokogiri/version.rb +106 -1
- data/lib/nokogiri/xml/attr.rb +14 -0
- data/lib/nokogiri/xml/attribute_decl.rb +18 -0
- data/lib/nokogiri/xml/builder.rb +395 -31
- data/lib/nokogiri/xml/cdata.rb +4 -2
- data/lib/nokogiri/xml/character_data.rb +7 -0
- data/lib/nokogiri/xml/document.rb +267 -12
- data/lib/nokogiri/xml/document_fragment.rb +149 -0
- data/lib/nokogiri/xml/dtd.rb +27 -1
- data/lib/nokogiri/xml/element_content.rb +36 -0
- data/lib/nokogiri/xml/element_decl.rb +13 -0
- data/lib/nokogiri/xml/entity_decl.rb +19 -0
- data/lib/nokogiri/xml/namespace.rb +13 -0
- data/lib/nokogiri/xml/node/save_options.rb +61 -0
- data/lib/nokogiri/xml/node.rb +748 -109
- data/lib/nokogiri/xml/node_set.rb +200 -72
- data/lib/nokogiri/xml/parse_options.rb +120 -0
- data/lib/nokogiri/xml/pp/character_data.rb +18 -0
- data/lib/nokogiri/xml/pp/node.rb +56 -0
- data/lib/nokogiri/xml/pp.rb +2 -0
- data/lib/nokogiri/xml/processing_instruction.rb +8 -0
- data/lib/nokogiri/xml/reader.rb +102 -4
- data/lib/nokogiri/xml/relax_ng.rb +32 -0
- data/lib/nokogiri/xml/sax/document.rb +114 -2
- data/lib/nokogiri/xml/sax/parser.rb +97 -7
- data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
- data/lib/nokogiri/xml/sax.rb +2 -7
- data/lib/nokogiri/xml/schema.rb +63 -0
- data/lib/nokogiri/xml/searchable.rb +221 -0
- data/lib/nokogiri/xml/syntax_error.rb +27 -1
- data/lib/nokogiri/xml/text.rb +4 -1
- data/lib/nokogiri/xml/xpath/syntax_error.rb +11 -0
- data/lib/nokogiri/xml/xpath.rb +4 -0
- data/lib/nokogiri/xml/xpath_context.rb +3 -1
- data/lib/nokogiri/xml.rb +45 -38
- data/lib/nokogiri/xslt/stylesheet.rb +19 -0
- data/lib/nokogiri/xslt.rb +47 -2
- data/lib/nokogiri.rb +117 -24
- data/lib/xsd/xmlparser/nokogiri.rb +102 -0
- data/patches/sort-patches-by-date +25 -0
- data/ports/archives/libxml2-2.9.4.tar.gz +0 -0
- data/ports/archives/libxslt-1.1.29.tar.gz +0 -0
- data/suppressions/README.txt +1 -0
- data/suppressions/nokogiri_ree-1.8.7.358.supp +61 -0
- data/suppressions/nokogiri_ruby-1.8.7.370.supp +0 -0
- data/suppressions/nokogiri_ruby-1.9.2.320.supp +28 -0
- data/suppressions/nokogiri_ruby-1.9.3.327.supp +28 -0
- data/tasks/test.rb +100 -0
- data/test/css/test_nthiness.rb +73 -6
- data/test/css/test_parser.rb +184 -39
- data/test/css/test_tokenizer.rb +72 -19
- data/test/css/test_xpath_visitor.rb +44 -2
- data/test/decorators/test_slop.rb +20 -0
- data/test/files/2ch.html +108 -0
- data/test/files/GH_1042.html +18 -0
- data/test/files/address_book.rlx +12 -0
- data/test/files/address_book.xml +10 -0
- data/test/files/atom.xml +344 -0
- data/test/files/bar/bar.xsd +4 -0
- data/test/files/bogus.xml +0 -0
- data/test/files/dont_hurt_em_why.xml +422 -0
- data/test/files/encoding.html +82 -0
- data/test/files/encoding.xhtml +84 -0
- data/test/files/exslt.xml +8 -0
- data/test/files/exslt.xslt +35 -0
- data/test/files/foo/foo.xsd +4 -0
- data/test/files/metacharset.html +10 -0
- data/test/files/namespace_pressure_test.xml +1684 -0
- data/test/files/noencoding.html +47 -0
- data/test/files/po.xml +32 -0
- data/test/files/po.xsd +66 -0
- data/test/files/saml/saml20assertion_schema.xsd +283 -0
- data/test/files/saml/saml20protocol_schema.xsd +302 -0
- data/test/files/saml/xenc_schema.xsd +146 -0
- data/test/files/saml/xmldsig_schema.xsd +318 -0
- data/test/files/shift_jis.html +10 -0
- data/test/files/shift_jis.xml +5 -0
- data/test/files/shift_jis_no_charset.html +9 -0
- data/test/files/slow-xpath.xml +25509 -0
- data/test/files/snuggles.xml +3 -0
- data/test/files/staff.dtd +10 -0
- data/test/files/test_document_url/bar.xml +2 -0
- data/test/files/test_document_url/document.dtd +4 -0
- data/test/files/test_document_url/document.xml +6 -0
- data/test/files/tlm.html +2 -1
- data/test/files/to_be_xincluded.xml +2 -0
- data/test/files/valid_bar.xml +2 -0
- data/test/files/xinclude.xml +4 -0
- data/test/helper.rb +124 -13
- data/test/html/sax/test_parser.rb +118 -4
- data/test/html/sax/test_parser_context.rb +46 -0
- data/test/html/sax/test_push_parser.rb +87 -0
- data/test/html/test_builder.rb +94 -8
- data/test/html/test_document.rb +626 -11
- data/test/html/test_document_encoding.rb +145 -0
- data/test/html/test_document_fragment.rb +301 -0
- data/test/html/test_element_description.rb +105 -0
- data/test/html/test_named_characters.rb +14 -0
- data/test/html/test_node.rb +212 -0
- data/test/html/test_node_encoding.rb +85 -0
- data/test/namespaces/test_additional_namespaces_in_builder_doc.rb +14 -0
- data/test/namespaces/test_namespaces_aliased_default.rb +24 -0
- data/test/namespaces/test_namespaces_in_builder_doc.rb +75 -0
- data/test/namespaces/test_namespaces_in_cloned_doc.rb +31 -0
- data/test/namespaces/test_namespaces_in_created_doc.rb +75 -0
- data/test/namespaces/test_namespaces_in_parsed_doc.rb +80 -0
- data/test/namespaces/test_namespaces_preservation.rb +31 -0
- data/test/test_convert_xpath.rb +2 -47
- data/test/test_css_cache.rb +45 -0
- data/test/test_encoding_handler.rb +48 -0
- data/test/test_memory_leak.rb +156 -0
- data/test/test_nokogiri.rb +103 -1
- data/test/test_soap4r_sax.rb +52 -0
- data/test/test_xslt_transforms.rb +293 -8
- data/test/xml/node/test_save_options.rb +28 -0
- data/test/xml/node/test_subclass.rb +44 -0
- data/test/xml/sax/test_parser.rb +309 -8
- data/test/xml/sax/test_parser_context.rb +115 -0
- data/test/xml/sax/test_push_parser.rb +157 -0
- data/test/xml/test_attr.rb +67 -0
- data/test/xml/test_attribute_decl.rb +86 -0
- data/test/xml/test_builder.rb +327 -2
- data/test/xml/test_c14n.rb +180 -0
- data/test/xml/test_cdata.rb +32 -2
- data/test/xml/test_comment.rb +40 -0
- data/test/xml/test_document.rb +846 -35
- data/test/xml/test_document_encoding.rb +31 -0
- data/test/xml/test_document_fragment.rb +271 -0
- data/test/xml/test_dtd.rb +153 -9
- data/test/xml/test_dtd_encoding.rb +31 -0
- data/test/xml/test_element_content.rb +56 -0
- data/test/xml/test_element_decl.rb +73 -0
- data/test/xml/test_entity_decl.rb +122 -0
- data/test/xml/test_entity_reference.rb +251 -0
- data/test/xml/test_namespace.rb +96 -0
- data/test/xml/test_node.rb +1126 -105
- data/test/xml/test_node_attributes.rb +115 -0
- data/test/xml/test_node_encoding.rb +69 -0
- data/test/xml/test_node_inheritance.rb +32 -0
- data/test/xml/test_node_reparenting.rb +549 -0
- data/test/xml/test_node_set.rb +668 -9
- data/test/xml/test_parse_options.rb +64 -0
- data/test/xml/test_processing_instruction.rb +30 -0
- data/test/xml/test_reader.rb +589 -0
- data/test/xml/test_reader_encoding.rb +134 -0
- data/test/xml/test_relax_ng.rb +60 -0
- data/test/xml/test_schema.rb +142 -0
- data/test/xml/test_syntax_error.rb +30 -0
- data/test/xml/test_text.rb +49 -2
- data/test/xml/test_unparented_node.rb +440 -0
- data/test/xml/test_xinclude.rb +83 -0
- data/test/xml/test_xpath.rb +445 -0
- data/test/xslt/test_custom_functions.rb +133 -0
- data/test/xslt/test_exception_handling.rb +37 -0
- data/test_all +107 -0
- metadata +459 -115
- data/History.txt +0 -6
- data/README.ja.txt +0 -86
- data/README.txt +0 -87
- data/ext/nokogiri/html_sax_parser.c +0 -32
- data/ext/nokogiri/html_sax_parser.h +0 -11
- data/ext/nokogiri/native.c +0 -40
- data/ext/nokogiri/native.h +0 -51
- data/ext/nokogiri/xml_xpath.c +0 -46
- data/ext/nokogiri/xml_xpath.h +0 -11
- data/lib/nokogiri/css/generated_parser.rb +0 -653
- data/lib/nokogiri/css/generated_tokenizer.rb +0 -159
- data/lib/nokogiri/decorators/hpricot/node.rb +0 -58
- data/lib/nokogiri/decorators/hpricot/node_set.rb +0 -14
- data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +0 -17
- data/lib/nokogiri/decorators/hpricot.rb +0 -3
- data/lib/nokogiri/decorators.rb +0 -1
- data/lib/nokogiri/hpricot.rb +0 -47
- data/lib/nokogiri/xml/after_handler.rb +0 -18
- data/lib/nokogiri/xml/before_handler.rb +0 -32
- data/lib/nokogiri/xml/element.rb +0 -6
- data/lib/nokogiri/xml/entity_declaration.rb +0 -9
- data/nokogiri.gemspec +0 -34
- data/test/hpricot/files/basic.xhtml +0 -17
- data/test/hpricot/files/boingboing.html +0 -2266
- data/test/hpricot/files/cy0.html +0 -3653
- data/test/hpricot/files/immob.html +0 -400
- data/test/hpricot/files/pace_application.html +0 -1320
- data/test/hpricot/files/tenderlove.html +0 -16
- data/test/hpricot/files/uswebgen.html +0 -220
- data/test/hpricot/files/utf8.html +0 -1054
- data/test/hpricot/files/week9.html +0 -1723
- data/test/hpricot/files/why.xml +0 -19
- data/test/hpricot/load_files.rb +0 -7
- data/test/hpricot/test_alter.rb +0 -67
- data/test/hpricot/test_builder.rb +0 -27
- data/test/hpricot/test_parser.rb +0 -423
- data/test/hpricot/test_paths.rb +0 -15
- data/test/hpricot/test_preserved.rb +0 -78
- data/test/hpricot/test_xml.rb +0 -30
- data/test/test_reader.rb +0 -222
data/test/test_convert_xpath.rb
CHANGED
@@ -1,35 +1,15 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'rubygems'
|
5
|
-
require 'hpricot'
|
6
|
-
HAS_HPRICOT = true
|
7
|
-
rescue LoadError
|
8
|
-
HAS_HPRICOT = false
|
9
|
-
end
|
1
|
+
require "helper"
|
10
2
|
|
11
3
|
class TestConvertXPath < Nokogiri::TestCase
|
12
4
|
|
13
5
|
def setup
|
6
|
+
super
|
14
7
|
@N = Nokogiri(File.read(HTML_FILE))
|
15
|
-
@NH = Nokogiri.Hpricot(File.read(HTML_FILE)) # decorated document
|
16
|
-
@H = Hpricot(File.read(HTML_FILE)) if HAS_HPRICOT
|
17
8
|
end
|
18
9
|
|
19
10
|
def assert_syntactical_equivalence(hpath, xpath, match, &blk)
|
20
11
|
blk ||= lambda {|j| j.first}
|
21
12
|
assert_equal match, blk.call(@N.search(xpath)), "xpath result did not match"
|
22
|
-
if HAS_HPRICOT
|
23
|
-
assert_equal match, blk.call(@H.search(hpath)), "hpath result did not match"
|
24
|
-
end
|
25
|
-
assert_equal [xpath], @NH.convert_to_xpath(hpath), "converted hpath did not match xpath"
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_ordinary_xpath_conversions
|
29
|
-
assert_equal(".//p", @NH.convert_to_xpath("p").first)
|
30
|
-
assert_equal(".//p", @NH.convert_to_xpath(:p).first)
|
31
|
-
assert_equal(".//p", @NH.convert_to_xpath("//p").first)
|
32
|
-
assert_equal(".//p", @NH.convert_to_xpath(".//p").first)
|
33
13
|
end
|
34
14
|
|
35
15
|
def test_child_tag
|
@@ -116,21 +96,6 @@ class TestConvertXPath < Nokogiri::TestCase
|
|
116
96
|
end
|
117
97
|
|
118
98
|
def test_positional
|
119
|
-
##
|
120
|
-
# we are intentionally NOT staying compatible with nth-and-friends, as Hpricot has an OB1 bug.
|
121
|
-
#
|
122
|
-
# assert_syntactical_equivalence("div > div:eq(0)", ".//div/div[position() = 1]", "\r\nTender Lovemaking\r\nThe act of making love, tenderly.\r\n") do |j|
|
123
|
-
# j.first.inner_text
|
124
|
-
# end
|
125
|
-
# assert_syntactical_equivalence("div/div:eq(0)", ".//div/div[position() = 1]", "\r\nTender Lovemaking\r\nThe act of making love, tenderly.\r\n") do |j|
|
126
|
-
# j.first.inner_text
|
127
|
-
# end
|
128
|
-
# assert_syntactical_equivalence("div/div:nth(0)", ".//div/div[position() = 1]", "\r\nTender Lovemaking\r\nThe act of making love, tenderly.\r\n") do |j|
|
129
|
-
# j.first.inner_text
|
130
|
-
# end
|
131
|
-
# assert_syntactical_equivalence("div/div:nth-of-type(0)", ".//div/div[position() = 1]", "\r\nTender Lovemaking\r\nThe act of making love, tenderly.\r\n") do |j|
|
132
|
-
# j.first.inner_text
|
133
|
-
# end
|
134
99
|
assert_syntactical_equivalence("div/div:first()", ".//div/div[position() = 1]", "\r\nTender Lovemaking\r\nThe act of making love, tenderly.\r\n".gsub(/[\r\n]/, '')) do |j|
|
135
100
|
j.first.inner_text.gsub(/[\r\n]/, '')
|
136
101
|
end
|
@@ -151,16 +116,6 @@ class TestConvertXPath < Nokogiri::TestCase
|
|
151
116
|
end
|
152
117
|
end
|
153
118
|
|
154
|
-
##
|
155
|
-
# 'and' is not supported by hpricot
|
156
|
-
# def test_and
|
157
|
-
# assert_syntactical_equivalence("div[h1 and small]", ".//div[h1 and small]", "\r\nTender Lovemaking\r\nThe act of making love, tenderly.\r\n") do |j|
|
158
|
-
# j.inner_text
|
159
|
-
# end
|
160
|
-
# end
|
161
|
-
|
162
|
-
|
163
|
-
|
164
119
|
# TODO:
|
165
120
|
# doc/'title ~ link' -> links that are siblings of title
|
166
121
|
# doc/'p[@class~="final"]' -> class includes string (whitespacy)
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class TestCssCache < Nokogiri::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
@css = "a1 > b2 > c3"
|
8
|
+
@parse_result = Nokogiri::CSS.parse(@css)
|
9
|
+
@to_xpath_result = @parse_result.map(&:to_xpath)
|
10
|
+
Nokogiri::CSS::Parser.class_eval do
|
11
|
+
class << @cache
|
12
|
+
alias :old_bracket :[]
|
13
|
+
attr_reader :count
|
14
|
+
def [](key)
|
15
|
+
@count ||= 0
|
16
|
+
@count += 1
|
17
|
+
old_bracket(key)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
assert Nokogiri::CSS::Parser.cache_on?
|
22
|
+
end
|
23
|
+
|
24
|
+
def teardown
|
25
|
+
Nokogiri::CSS::Parser.clear_cache
|
26
|
+
Nokogiri::CSS::Parser.set_cache true
|
27
|
+
end
|
28
|
+
|
29
|
+
[ false, true ].each do |cache_setting|
|
30
|
+
define_method "test_css_cache_#{cache_setting ? "true" : "false"}" do
|
31
|
+
times = cache_setting ? 4 : nil
|
32
|
+
|
33
|
+
Nokogiri::CSS::Parser.set_cache cache_setting
|
34
|
+
|
35
|
+
Nokogiri::CSS.xpath_for(@css)
|
36
|
+
Nokogiri::CSS.xpath_for(@css)
|
37
|
+
Nokogiri::CSS::Parser.new.xpath_for(@css)
|
38
|
+
Nokogiri::CSS::Parser.new.xpath_for(@css)
|
39
|
+
|
40
|
+
assert_equal(times, Nokogiri::CSS::Parser.class_eval { @cache.count })
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require "helper"
|
4
|
+
|
5
|
+
class TestEncodingHandler < Nokogiri::TestCase
|
6
|
+
def teardown
|
7
|
+
Nokogiri::EncodingHandler.clear_aliases!
|
8
|
+
#Replace default aliases removed by clear_aliases!
|
9
|
+
Nokogiri.install_default_aliases
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_get
|
13
|
+
assert_not_nil Nokogiri::EncodingHandler['UTF-8']
|
14
|
+
assert_nil Nokogiri::EncodingHandler['alsdkjfhaldskjfh']
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_name
|
18
|
+
eh = Nokogiri::EncodingHandler['UTF-8']
|
19
|
+
assert_equal "UTF-8", eh.name
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_alias
|
23
|
+
Nokogiri::EncodingHandler.alias('UTF-8', 'UTF-18')
|
24
|
+
assert_equal 'UTF-8', Nokogiri::EncodingHandler['UTF-18'].name
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_cleanup_aliases
|
28
|
+
assert_nil Nokogiri::EncodingHandler['UTF-9']
|
29
|
+
Nokogiri::EncodingHandler.alias('UTF-8', 'UTF-9')
|
30
|
+
assert_not_nil Nokogiri::EncodingHandler['UTF-9']
|
31
|
+
|
32
|
+
Nokogiri::EncodingHandler.clear_aliases!
|
33
|
+
assert_nil Nokogiri::EncodingHandler['UTF-9']
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_delete
|
37
|
+
assert_nil Nokogiri::EncodingHandler['UTF-9']
|
38
|
+
Nokogiri::EncodingHandler.alias('UTF-8', 'UTF-9')
|
39
|
+
assert_not_nil Nokogiri::EncodingHandler['UTF-9']
|
40
|
+
|
41
|
+
Nokogiri::EncodingHandler.delete 'UTF-9'
|
42
|
+
assert_nil Nokogiri::EncodingHandler['UTF-9']
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_delete_non_existent
|
46
|
+
assert_nil Nokogiri::EncodingHandler.delete('UTF-9')
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class TestMemoryLeak < Nokogiri::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@str = <<EOF
|
7
|
+
<!DOCTYPE HTML>
|
8
|
+
<html>
|
9
|
+
<body>
|
10
|
+
<br />
|
11
|
+
</body>
|
12
|
+
</html>
|
13
|
+
EOF
|
14
|
+
end
|
15
|
+
|
16
|
+
if ENV['NOKOGIRI_GC'] # turning these off by default for now
|
17
|
+
def test_dont_hurt_em_why
|
18
|
+
content = File.open("#{File.dirname(__FILE__)}/files/dont_hurt_em_why.xml").read
|
19
|
+
ndoc = Nokogiri::XML(content)
|
20
|
+
2.times do
|
21
|
+
ndoc.search('status text').first.inner_text
|
22
|
+
ndoc.search('user name').first.inner_text
|
23
|
+
GC.start
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class BadIO
|
28
|
+
def read(*args)
|
29
|
+
raise 'hell'
|
30
|
+
end
|
31
|
+
|
32
|
+
def write(*args)
|
33
|
+
raise 'chickens'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_for_mem_leak_on_io_callbacks
|
38
|
+
io = File.open SNUGGLES_FILE
|
39
|
+
Nokogiri::XML.parse(io)
|
40
|
+
|
41
|
+
loop do
|
42
|
+
Nokogiri::XML.parse(BadIO.new) rescue nil
|
43
|
+
doc.write BadIO.new rescue nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_for_memory_leak
|
48
|
+
begin
|
49
|
+
# we don't use Dike in any tests, but requiring it has side effects
|
50
|
+
# that can create memory leaks, and that's what we're testing for.
|
51
|
+
require 'rubygems'
|
52
|
+
require 'dike' # do not remove!
|
53
|
+
|
54
|
+
count_start = count_object_space_documents
|
55
|
+
xml_data = <<-EOS
|
56
|
+
<test>
|
57
|
+
<items>
|
58
|
+
<item>abc</item>
|
59
|
+
<item>1234</item>
|
60
|
+
<item>Zzz</item>
|
61
|
+
<items>
|
62
|
+
</test>
|
63
|
+
EOS
|
64
|
+
20.times do
|
65
|
+
doc = Nokogiri::XML(xml_data)
|
66
|
+
doc.xpath("//item")
|
67
|
+
end
|
68
|
+
2.times { GC.start }
|
69
|
+
count_end = count_object_space_documents
|
70
|
+
assert((count_end - count_start) <= 2, "memory leak detected")
|
71
|
+
rescue LoadError
|
72
|
+
puts "\ndike is not installed, skipping memory leak test"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_node_set_namespace_mem_leak
|
77
|
+
xml = Nokogiri::XML "<foo></foo>"
|
78
|
+
ctx = Nokogiri::XML::XPathContext.new(xml)
|
79
|
+
loop do
|
80
|
+
ctx.evaluate("//namespace::*")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_leak_on_node_replace
|
85
|
+
loop do
|
86
|
+
doc = Nokogiri.XML("<root><foo /></root>")
|
87
|
+
n = Nokogiri::XML::CDATA.new(doc, "bar")
|
88
|
+
pivot = doc.root.children[0]
|
89
|
+
pivot.replace(n)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_sax_parser_context
|
94
|
+
io = StringIO.new(@str)
|
95
|
+
|
96
|
+
loop do
|
97
|
+
Nokogiri::XML::SAX::ParserContext.new(@str)
|
98
|
+
Nokogiri::XML::SAX::ParserContext.new(io)
|
99
|
+
io.rewind
|
100
|
+
|
101
|
+
Nokogiri::HTML::SAX::ParserContext.new(@str)
|
102
|
+
Nokogiri::HTML::SAX::ParserContext.new(io)
|
103
|
+
io.rewind
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class JumpingSaxHandler < Nokogiri::XML::SAX::Document
|
108
|
+
def initialize(jumptag)
|
109
|
+
@jumptag = jumptag
|
110
|
+
super()
|
111
|
+
end
|
112
|
+
|
113
|
+
def start_element(name, attrs = [])
|
114
|
+
throw @jumptag
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_jumping_sax_handler
|
119
|
+
doc = JumpingSaxHandler.new(:foo)
|
120
|
+
|
121
|
+
loop do
|
122
|
+
catch(:foo) do
|
123
|
+
Nokogiri::HTML::SAX::Parser.new(doc).parse(@str)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_in_context_parser_leak
|
129
|
+
loop do
|
130
|
+
doc = Nokogiri::XML::Document.new
|
131
|
+
fragment1 = Nokogiri::XML::DocumentFragment.new(doc, '<foo/>')
|
132
|
+
node = fragment1.children[0]
|
133
|
+
node.parse('<bar></bar>')
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_in_context_parser_leak_ii
|
138
|
+
loop { Nokogiri::XML('<a/>').root.parse('<b/>') }
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_leak_on_xpath_string_function
|
142
|
+
doc = Nokogiri::XML(@str)
|
143
|
+
loop do
|
144
|
+
doc.xpath('name(//node())')
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end # if NOKOGIRI_GC
|
148
|
+
|
149
|
+
private
|
150
|
+
|
151
|
+
def count_object_space_documents
|
152
|
+
count = 0
|
153
|
+
ObjectSpace.each_object {|j| count += 1 if j.is_a?(Nokogiri::XML::Document) }
|
154
|
+
count
|
155
|
+
end
|
156
|
+
end
|
data/test/test_nokogiri.rb
CHANGED
@@ -1,12 +1,52 @@
|
|
1
|
-
require
|
1
|
+
require "helper"
|
2
2
|
|
3
3
|
class TestNokogiri < Nokogiri::TestCase
|
4
|
+
def test_versions
|
5
|
+
version_match = /\d+\.\d+\.\d+/
|
6
|
+
assert_match version_match, Nokogiri::VERSION
|
7
|
+
|
8
|
+
assert_equal Nokogiri::VERSION_INFO['ruby']['version'], ::RUBY_VERSION
|
9
|
+
assert_equal Nokogiri::VERSION_INFO['ruby']['platform'], ::RUBY_PLATFORM
|
10
|
+
|
11
|
+
if Nokogiri.uses_libxml?
|
12
|
+
assert_match version_match, Nokogiri::LIBXML_VERSION
|
13
|
+
assert_equal 'extension', Nokogiri::VERSION_INFO['libxml']['binding']
|
14
|
+
|
15
|
+
assert_match version_match, Nokogiri::VERSION_INFO['libxml']['compiled']
|
16
|
+
assert_equal Nokogiri::LIBXML_VERSION, Nokogiri::VERSION_INFO['libxml']['compiled']
|
17
|
+
|
18
|
+
assert_match version_match, Nokogiri::VERSION_INFO['libxml']['loaded']
|
19
|
+
Nokogiri::LIBXML_PARSER_VERSION =~ /(\d)(\d{2})(\d{2})/
|
20
|
+
major = $1.to_i
|
21
|
+
minor = $2.to_i
|
22
|
+
bug = $3.to_i
|
23
|
+
assert_equal "#{major}.#{minor}.#{bug}", Nokogiri::VERSION_INFO['libxml']['loaded']
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_libxml_iconv
|
28
|
+
assert Nokogiri.const_defined?(:LIBXML_ICONV_ENABLED) if Nokogiri.uses_libxml?
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_parse_with_io
|
32
|
+
doc = Nokogiri.parse(
|
33
|
+
StringIO.new("<html><head><title></title><body></body></html>")
|
34
|
+
)
|
35
|
+
assert_instance_of Nokogiri::HTML::Document, doc
|
36
|
+
end
|
37
|
+
|
4
38
|
def test_xml?
|
5
39
|
doc = Nokogiri.parse(File.read(XML_FILE))
|
6
40
|
assert doc.xml?
|
7
41
|
assert !doc.html?
|
8
42
|
end
|
9
43
|
|
44
|
+
def test_atom_is_xml?
|
45
|
+
doc = Nokogiri.parse(File.read(XML_ATOM_FILE))
|
46
|
+
assert doc.xml?
|
47
|
+
assert !doc.html?
|
48
|
+
end
|
49
|
+
|
10
50
|
def test_html?
|
11
51
|
doc = Nokogiri.parse(File.read(HTML_FILE))
|
12
52
|
assert !doc.xml?
|
@@ -33,4 +73,66 @@ class TestNokogiri < Nokogiri::TestCase
|
|
33
73
|
doc = Nokogiri.make { b "bold tag" }
|
34
74
|
assert_equal('<b>bold tag</b>', doc.to_html.chomp)
|
35
75
|
end
|
76
|
+
|
77
|
+
SLOP_HTML = <<-END
|
78
|
+
<html>
|
79
|
+
<body>
|
80
|
+
<ul>
|
81
|
+
<li class='red'>one</li>
|
82
|
+
<li class='blue'>two</li>
|
83
|
+
</ul>
|
84
|
+
<div>
|
85
|
+
one
|
86
|
+
<div>div two</div>
|
87
|
+
</div>
|
88
|
+
</body>
|
89
|
+
</html>
|
90
|
+
END
|
91
|
+
|
92
|
+
def test_slop_css
|
93
|
+
doc = Nokogiri::Slop(<<-eohtml)
|
94
|
+
<html>
|
95
|
+
<body>
|
96
|
+
<div>
|
97
|
+
one
|
98
|
+
<div class='foo'>
|
99
|
+
div two
|
100
|
+
<div class='foo'>
|
101
|
+
div three
|
102
|
+
</div>
|
103
|
+
</div>
|
104
|
+
</div>
|
105
|
+
</body>
|
106
|
+
</html>
|
107
|
+
eohtml
|
108
|
+
assert_equal "div", doc.html.body.div.div('.foo').name
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_slop
|
112
|
+
doc = Nokogiri::Slop(SLOP_HTML)
|
113
|
+
|
114
|
+
assert_equal "one", doc.html.body.ul.li.first.text
|
115
|
+
assert_equal "two", doc.html.body.ul.li(".blue").text
|
116
|
+
assert_equal "div two", doc.html.body.div.div.text
|
117
|
+
|
118
|
+
assert_equal "two", doc.html.body.ul.li(:css => ".blue").text
|
119
|
+
|
120
|
+
assert_equal "two", doc.html.body.ul.li(:xpath => "position()=2").text
|
121
|
+
assert_equal "one", doc.html.body.ul.li(:xpath => ["contains(text(),'o')"]).first.text
|
122
|
+
assert_equal "two", doc.html.body.ul.li(:xpath => ["contains(text(),'o')","contains(text(),'t')"]).text
|
123
|
+
|
124
|
+
assert_raise(NoMethodError) { doc.nonexistent }
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_slop_decorator
|
128
|
+
doc = Nokogiri(SLOP_HTML)
|
129
|
+
assert !doc.decorators(Nokogiri::XML::Node).include?(Nokogiri::Decorators::Slop)
|
130
|
+
|
131
|
+
doc.slop!
|
132
|
+
assert doc.decorators(Nokogiri::XML::Node).include?(Nokogiri::Decorators::Slop)
|
133
|
+
|
134
|
+
doc.slop!
|
135
|
+
assert_equal 1, doc.decorators(Nokogiri::XML::Node).select { |d| d == Nokogiri::Decorators::Slop }.size
|
136
|
+
end
|
137
|
+
|
36
138
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
module XSD
|
4
|
+
module XMLParser
|
5
|
+
class Parser
|
6
|
+
@factory_added = nil
|
7
|
+
|
8
|
+
class << self; attr_reader :factory_added; end
|
9
|
+
|
10
|
+
def self.add_factory o
|
11
|
+
@factory_added = o
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize *args
|
15
|
+
@charset = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def characters foo
|
19
|
+
end
|
20
|
+
|
21
|
+
def start_element *args
|
22
|
+
end
|
23
|
+
|
24
|
+
def end_element *args
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
require 'xsd/xmlparser/nokogiri'
|
31
|
+
|
32
|
+
class TestSoap4rSax < Nokogiri::TestCase
|
33
|
+
def test_factory_added
|
34
|
+
assert_equal XSD::XMLParser::Nokogiri, XSD::XMLParser::Nokogiri.factory_added
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_parse
|
38
|
+
o = Class.new(::XSD::XMLParser::Nokogiri) do
|
39
|
+
attr_accessor :element_started
|
40
|
+
def initialize *args
|
41
|
+
super
|
42
|
+
@element_started = false
|
43
|
+
end
|
44
|
+
|
45
|
+
def start_element *args
|
46
|
+
@element_started = true
|
47
|
+
end
|
48
|
+
end.new 'foo'
|
49
|
+
o.do_parse '<?xml version="1.0" ?><root xmlns="http://example.com/"/>'
|
50
|
+
assert o.element_started, 'element started'
|
51
|
+
end
|
52
|
+
end
|