nokogiri 1.8.5 → 1.15.3
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/Gemfile +40 -18
- data/LICENSE-DEPENDENCIES.md +1636 -1024
- data/LICENSE.md +5 -28
- data/README.md +203 -90
- data/bin/nokogiri +63 -50
- data/dependencies.yml +33 -61
- data/ext/nokogiri/depend +38 -358
- data/ext/nokogiri/extconf.rb +867 -417
- data/ext/nokogiri/gumbo.c +594 -0
- data/ext/nokogiri/html4_document.c +165 -0
- data/ext/nokogiri/html4_element_description.c +299 -0
- data/ext/nokogiri/html4_entity_lookup.c +37 -0
- data/ext/nokogiri/html4_sax_parser_context.c +108 -0
- data/ext/nokogiri/html4_sax_push_parser.c +95 -0
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +251 -105
- data/ext/nokogiri/nokogiri.h +215 -90
- data/ext/nokogiri/test_global_handlers.c +40 -0
- data/ext/nokogiri/xml_attr.c +42 -37
- data/ext/nokogiri/xml_attribute_decl.c +22 -22
- data/ext/nokogiri/xml_cdata.c +40 -31
- data/ext/nokogiri/xml_comment.c +20 -27
- data/ext/nokogiri/xml_document.c +401 -237
- data/ext/nokogiri/xml_document_fragment.c +13 -17
- data/ext/nokogiri/xml_dtd.c +64 -58
- data/ext/nokogiri/xml_element_content.c +63 -55
- data/ext/nokogiri/xml_element_decl.c +31 -31
- data/ext/nokogiri/xml_encoding_handler.c +54 -21
- data/ext/nokogiri/xml_entity_decl.c +37 -35
- data/ext/nokogiri/xml_entity_reference.c +17 -19
- data/ext/nokogiri/xml_namespace.c +136 -62
- data/ext/nokogiri/xml_node.c +1387 -678
- data/ext/nokogiri/xml_node_set.c +246 -216
- data/ext/nokogiri/xml_processing_instruction.c +18 -20
- data/ext/nokogiri/xml_reader.c +347 -212
- data/ext/nokogiri/xml_relax_ng.c +86 -77
- data/ext/nokogiri/xml_sax_parser.c +149 -124
- data/ext/nokogiri/xml_sax_parser_context.c +145 -103
- data/ext/nokogiri/xml_sax_push_parser.c +64 -36
- data/ext/nokogiri/xml_schema.c +138 -81
- data/ext/nokogiri/xml_syntax_error.c +42 -21
- data/ext/nokogiri/xml_text.c +36 -26
- data/ext/nokogiri/xml_xpath_context.c +366 -178
- data/ext/nokogiri/xslt_stylesheet.c +335 -189
- data/gumbo-parser/CHANGES.md +63 -0
- data/gumbo-parser/Makefile +111 -0
- data/gumbo-parser/THANKS +27 -0
- data/gumbo-parser/src/Makefile +34 -0
- data/gumbo-parser/src/README.md +41 -0
- data/gumbo-parser/src/ascii.c +75 -0
- data/gumbo-parser/src/ascii.h +115 -0
- data/gumbo-parser/src/attribute.c +42 -0
- data/gumbo-parser/src/attribute.h +17 -0
- data/gumbo-parser/src/char_ref.c +22225 -0
- data/gumbo-parser/src/char_ref.h +29 -0
- data/gumbo-parser/src/char_ref.rl +2154 -0
- data/gumbo-parser/src/error.c +630 -0
- data/gumbo-parser/src/error.h +148 -0
- data/gumbo-parser/src/foreign_attrs.c +103 -0
- data/gumbo-parser/src/foreign_attrs.gperf +27 -0
- data/gumbo-parser/src/insertion_mode.h +33 -0
- data/gumbo-parser/src/macros.h +91 -0
- data/gumbo-parser/src/nokogiri_gumbo.h +944 -0
- data/gumbo-parser/src/parser.c +4891 -0
- data/gumbo-parser/src/parser.h +41 -0
- data/gumbo-parser/src/replacement.h +33 -0
- data/gumbo-parser/src/string_buffer.c +103 -0
- data/gumbo-parser/src/string_buffer.h +68 -0
- data/gumbo-parser/src/string_piece.c +48 -0
- data/gumbo-parser/src/svg_attrs.c +174 -0
- data/gumbo-parser/src/svg_attrs.gperf +77 -0
- data/gumbo-parser/src/svg_tags.c +137 -0
- data/gumbo-parser/src/svg_tags.gperf +55 -0
- data/gumbo-parser/src/tag.c +223 -0
- data/gumbo-parser/src/tag_lookup.c +382 -0
- data/gumbo-parser/src/tag_lookup.gperf +170 -0
- data/gumbo-parser/src/tag_lookup.h +13 -0
- data/gumbo-parser/src/token_buffer.c +79 -0
- data/gumbo-parser/src/token_buffer.h +71 -0
- data/gumbo-parser/src/token_type.h +17 -0
- data/gumbo-parser/src/tokenizer.c +3463 -0
- data/gumbo-parser/src/tokenizer.h +112 -0
- data/gumbo-parser/src/tokenizer_states.h +339 -0
- data/gumbo-parser/src/utf8.c +245 -0
- data/gumbo-parser/src/utf8.h +164 -0
- data/gumbo-parser/src/util.c +66 -0
- data/gumbo-parser/src/util.h +34 -0
- data/gumbo-parser/src/vector.c +111 -0
- data/gumbo-parser/src/vector.h +45 -0
- data/lib/nokogiri/class_resolver.rb +67 -0
- data/lib/nokogiri/css/node.rb +10 -8
- data/lib/nokogiri/css/parser.rb +397 -377
- data/lib/nokogiri/css/parser.y +250 -245
- data/lib/nokogiri/css/parser_extras.rb +54 -49
- data/lib/nokogiri/css/syntax_error.rb +3 -1
- data/lib/nokogiri/css/tokenizer.rb +107 -104
- data/lib/nokogiri/css/tokenizer.rex +3 -2
- data/lib/nokogiri/css/xpath_visitor.rb +224 -95
- data/lib/nokogiri/css.rb +56 -17
- data/lib/nokogiri/decorators/slop.rb +9 -7
- data/lib/nokogiri/encoding_handler.rb +57 -0
- data/lib/nokogiri/extension.rb +32 -0
- data/lib/nokogiri/gumbo.rb +15 -0
- data/lib/nokogiri/html.rb +38 -27
- data/lib/nokogiri/{html → html4}/builder.rb +4 -2
- data/lib/nokogiri/html4/document.rb +214 -0
- data/lib/nokogiri/html4/document_fragment.rb +54 -0
- data/lib/nokogiri/{html → html4}/element_description.rb +3 -1
- data/lib/nokogiri/html4/element_description_defaults.rb +2040 -0
- data/lib/nokogiri/html4/encoding_reader.rb +121 -0
- data/lib/nokogiri/{html → html4}/entity_lookup.rb +4 -2
- data/lib/nokogiri/{html → html4}/sax/parser.rb +17 -16
- data/lib/nokogiri/html4/sax/parser_context.rb +20 -0
- data/lib/nokogiri/{html → html4}/sax/push_parser.rb +12 -11
- data/lib/nokogiri/html4.rb +47 -0
- data/lib/nokogiri/html5/document.rb +168 -0
- data/lib/nokogiri/html5/document_fragment.rb +90 -0
- data/lib/nokogiri/html5/node.rb +103 -0
- data/lib/nokogiri/html5.rb +392 -0
- data/lib/nokogiri/jruby/dependencies.rb +3 -0
- data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
- data/lib/nokogiri/syntax_error.rb +2 -0
- data/lib/nokogiri/version/constant.rb +6 -0
- data/lib/nokogiri/version/info.rb +223 -0
- data/lib/nokogiri/version.rb +3 -108
- data/lib/nokogiri/xml/attr.rb +55 -3
- data/lib/nokogiri/xml/attribute_decl.rb +6 -2
- data/lib/nokogiri/xml/builder.rb +98 -54
- data/lib/nokogiri/xml/cdata.rb +3 -1
- data/lib/nokogiri/xml/character_data.rb +2 -0
- data/lib/nokogiri/xml/document.rb +312 -126
- data/lib/nokogiri/xml/document_fragment.rb +104 -48
- data/lib/nokogiri/xml/dtd.rb +4 -2
- data/lib/nokogiri/xml/element_content.rb +12 -2
- data/lib/nokogiri/xml/element_decl.rb +6 -2
- data/lib/nokogiri/xml/entity_decl.rb +7 -3
- data/lib/nokogiri/xml/entity_reference.rb +2 -0
- data/lib/nokogiri/xml/namespace.rb +45 -0
- data/lib/nokogiri/xml/node/save_options.rb +23 -8
- data/lib/nokogiri/xml/node.rb +1093 -411
- data/lib/nokogiri/xml/node_set.rb +173 -67
- data/lib/nokogiri/xml/notation.rb +13 -0
- data/lib/nokogiri/xml/parse_options.rb +145 -52
- data/lib/nokogiri/xml/pp/character_data.rb +9 -6
- data/lib/nokogiri/xml/pp/node.rb +42 -30
- data/lib/nokogiri/xml/pp.rb +4 -2
- data/lib/nokogiri/xml/processing_instruction.rb +4 -1
- data/lib/nokogiri/xml/reader.rb +21 -28
- data/lib/nokogiri/xml/relax_ng.rb +8 -2
- data/lib/nokogiri/xml/sax/document.rb +45 -49
- data/lib/nokogiri/xml/sax/parser.rb +39 -36
- data/lib/nokogiri/xml/sax/parser_context.rb +8 -3
- data/lib/nokogiri/xml/sax/push_parser.rb +6 -5
- data/lib/nokogiri/xml/sax.rb +6 -4
- data/lib/nokogiri/xml/schema.rb +19 -9
- data/lib/nokogiri/xml/searchable.rb +120 -72
- data/lib/nokogiri/xml/syntax_error.rb +6 -4
- data/lib/nokogiri/xml/text.rb +2 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +4 -2
- data/lib/nokogiri/xml/xpath.rb +15 -4
- data/lib/nokogiri/xml/xpath_context.rb +3 -3
- data/lib/nokogiri/xml.rb +38 -37
- data/lib/nokogiri/xslt/stylesheet.rb +3 -1
- data/lib/nokogiri/xslt.rb +101 -22
- data/lib/nokogiri.rb +59 -75
- data/lib/xsd/xmlparser/nokogiri.rb +29 -25
- data/patches/libxml2/0001-Remove-script-macro-support.patch +40 -0
- data/patches/libxml2/0002-Update-entities-to-remove-handling-of-ssi.patch +44 -0
- data/patches/libxml2/0003-libxml2.la-is-in-top_builddir.patch +25 -0
- data/patches/libxml2/0009-allow-wildcard-namespaces.patch +77 -0
- data/patches/libxml2/0010-update-config.guess-and-config.sub-for-libxml2.patch +224 -0
- data/patches/libxml2/0011-rip-out-libxml2-s-libc_single_threaded-support.patch +30 -0
- data/patches/libxslt/0001-update-config.guess-and-config.sub-for-libxslt.patch +224 -0
- data/ports/archives/libxml2-2.11.4.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.38.tar.xz +0 -0
- metadata +126 -399
- data/.autotest +0 -22
- data/.cross_rubies +0 -8
- data/.editorconfig +0 -17
- data/.gemtest +0 -0
- data/.travis.yml +0 -63
- data/CHANGELOG.md +0 -1368
- data/CONTRIBUTING.md +0 -42
- data/C_CODING_STYLE.rdoc +0 -33
- data/Gemfile-libxml-ruby +0 -3
- data/Manifest.txt +0 -370
- data/ROADMAP.md +0 -111
- data/Rakefile +0 -348
- data/SECURITY.md +0 -19
- data/STANDARD_RESPONSES.md +0 -47
- data/Y_U_NO_GEMSPEC.md +0 -155
- data/appveyor.yml +0 -29
- data/build_all +0 -44
- data/ext/nokogiri/html_document.c +0 -170
- data/ext/nokogiri/html_document.h +0 -10
- data/ext/nokogiri/html_element_description.c +0 -279
- data/ext/nokogiri/html_element_description.h +0 -10
- data/ext/nokogiri/html_entity_lookup.c +0 -32
- data/ext/nokogiri/html_entity_lookup.h +0 -8
- data/ext/nokogiri/html_sax_parser_context.c +0 -116
- data/ext/nokogiri/html_sax_parser_context.h +0 -11
- data/ext/nokogiri/html_sax_push_parser.c +0 -87
- data/ext/nokogiri/html_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_attr.h +0 -9
- data/ext/nokogiri/xml_attribute_decl.h +0 -9
- data/ext/nokogiri/xml_cdata.h +0 -9
- data/ext/nokogiri/xml_comment.h +0 -9
- data/ext/nokogiri/xml_document.h +0 -23
- data/ext/nokogiri/xml_document_fragment.h +0 -10
- data/ext/nokogiri/xml_dtd.h +0 -10
- data/ext/nokogiri/xml_element_content.h +0 -10
- data/ext/nokogiri/xml_element_decl.h +0 -9
- data/ext/nokogiri/xml_encoding_handler.h +0 -8
- data/ext/nokogiri/xml_entity_decl.h +0 -10
- data/ext/nokogiri/xml_entity_reference.h +0 -9
- data/ext/nokogiri/xml_io.c +0 -61
- data/ext/nokogiri/xml_io.h +0 -11
- data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
- data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
- data/ext/nokogiri/xml_namespace.h +0 -15
- data/ext/nokogiri/xml_node.h +0 -13
- data/ext/nokogiri/xml_node_set.h +0 -12
- data/ext/nokogiri/xml_processing_instruction.h +0 -9
- data/ext/nokogiri/xml_reader.h +0 -10
- data/ext/nokogiri/xml_relax_ng.h +0 -9
- data/ext/nokogiri/xml_sax_parser.h +0 -39
- data/ext/nokogiri/xml_sax_parser_context.h +0 -10
- data/ext/nokogiri/xml_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_schema.h +0 -9
- data/ext/nokogiri/xml_syntax_error.h +0 -13
- data/ext/nokogiri/xml_text.h +0 -9
- data/ext/nokogiri/xml_xpath_context.h +0 -10
- data/ext/nokogiri/xslt_stylesheet.h +0 -14
- data/lib/nokogiri/html/document.rb +0 -335
- data/lib/nokogiri/html/document_fragment.rb +0 -49
- data/lib/nokogiri/html/element_description_defaults.rb +0 -671
- data/lib/nokogiri/html/sax/parser_context.rb +0 -16
- data/patches/libxml2/0001-Revert-Do-not-URI-escape-in-server-side-includes.patch +0 -78
- data/patches/libxml2/0002-Fix-nullptr-deref-with-XPath-logic-ops.patch +0 -54
- data/patches/libxml2/0003-Fix-infinite-loop-in-LZMA-decompression.patch +0 -50
- data/patches/sort-patches-by-date +0 -25
- data/ports/archives/libxml2-2.9.8.tar.gz +0 -0
- data/ports/archives/libxslt-1.1.32.tar.gz +0 -0
- data/suppressions/README.txt +0 -1
- data/suppressions/nokogiri_ruby-2.supp +0 -10
- data/tasks/test.rb +0 -100
- data/test/css/test_nthiness.rb +0 -226
- data/test/css/test_parser.rb +0 -386
- data/test/css/test_tokenizer.rb +0 -215
- data/test/css/test_xpath_visitor.rb +0 -96
- data/test/decorators/test_slop.rb +0 -23
- data/test/files/2ch.html +0 -108
- data/test/files/GH_1042.html +0 -18
- data/test/files/address_book.rlx +0 -12
- data/test/files/address_book.xml +0 -10
- data/test/files/atom.xml +0 -344
- data/test/files/bar/bar.xsd +0 -4
- data/test/files/bogus.xml +0 -0
- data/test/files/dont_hurt_em_why.xml +0 -422
- data/test/files/encoding.html +0 -82
- data/test/files/encoding.xhtml +0 -84
- data/test/files/exslt.xml +0 -8
- data/test/files/exslt.xslt +0 -35
- data/test/files/foo/foo.xsd +0 -4
- data/test/files/metacharset.html +0 -10
- data/test/files/namespace_pressure_test.xml +0 -1684
- data/test/files/noencoding.html +0 -47
- data/test/files/po.xml +0 -32
- data/test/files/po.xsd +0 -66
- data/test/files/saml/saml20assertion_schema.xsd +0 -283
- data/test/files/saml/saml20protocol_schema.xsd +0 -302
- data/test/files/saml/xenc_schema.xsd +0 -146
- data/test/files/saml/xmldsig_schema.xsd +0 -318
- data/test/files/shift_jis.html +0 -10
- data/test/files/shift_jis.xml +0 -5
- data/test/files/shift_jis_no_charset.html +0 -9
- data/test/files/slow-xpath.xml +0 -25509
- data/test/files/snuggles.xml +0 -3
- data/test/files/staff.dtd +0 -10
- data/test/files/staff.xml +0 -59
- data/test/files/staff.xslt +0 -32
- data/test/files/test_document_url/bar.xml +0 -2
- data/test/files/test_document_url/document.dtd +0 -4
- data/test/files/test_document_url/document.xml +0 -6
- data/test/files/tlm.html +0 -851
- data/test/files/to_be_xincluded.xml +0 -2
- data/test/files/valid_bar.xml +0 -2
- data/test/files/xinclude.xml +0 -4
- data/test/helper.rb +0 -271
- data/test/html/sax/test_parser.rb +0 -168
- data/test/html/sax/test_parser_context.rb +0 -46
- data/test/html/sax/test_parser_text.rb +0 -163
- data/test/html/sax/test_push_parser.rb +0 -87
- data/test/html/test_attributes.rb +0 -85
- data/test/html/test_builder.rb +0 -164
- data/test/html/test_document.rb +0 -712
- data/test/html/test_document_encoding.rb +0 -143
- data/test/html/test_document_fragment.rb +0 -310
- data/test/html/test_element_description.rb +0 -105
- data/test/html/test_named_characters.rb +0 -14
- data/test/html/test_node.rb +0 -212
- data/test/html/test_node_encoding.rb +0 -91
- data/test/namespaces/test_additional_namespaces_in_builder_doc.rb +0 -14
- data/test/namespaces/test_namespaces_aliased_default.rb +0 -24
- data/test/namespaces/test_namespaces_in_builder_doc.rb +0 -75
- data/test/namespaces/test_namespaces_in_cloned_doc.rb +0 -31
- data/test/namespaces/test_namespaces_in_created_doc.rb +0 -75
- data/test/namespaces/test_namespaces_in_parsed_doc.rb +0 -80
- data/test/namespaces/test_namespaces_preservation.rb +0 -31
- data/test/test_convert_xpath.rb +0 -135
- data/test/test_css_cache.rb +0 -47
- data/test/test_encoding_handler.rb +0 -48
- data/test/test_memory_leak.rb +0 -156
- data/test/test_nokogiri.rb +0 -138
- data/test/test_soap4r_sax.rb +0 -52
- data/test/test_xslt_transforms.rb +0 -314
- data/test/xml/node/test_save_options.rb +0 -28
- data/test/xml/node/test_subclass.rb +0 -44
- data/test/xml/sax/test_parser.rb +0 -402
- data/test/xml/sax/test_parser_context.rb +0 -115
- data/test/xml/sax/test_parser_text.rb +0 -202
- data/test/xml/sax/test_push_parser.rb +0 -265
- data/test/xml/test_attr.rb +0 -74
- data/test/xml/test_attribute_decl.rb +0 -86
- data/test/xml/test_builder.rb +0 -341
- data/test/xml/test_c14n.rb +0 -180
- data/test/xml/test_cdata.rb +0 -54
- data/test/xml/test_comment.rb +0 -40
- data/test/xml/test_document.rb +0 -982
- data/test/xml/test_document_encoding.rb +0 -31
- data/test/xml/test_document_fragment.rb +0 -298
- data/test/xml/test_dtd.rb +0 -187
- data/test/xml/test_dtd_encoding.rb +0 -31
- data/test/xml/test_element_content.rb +0 -56
- data/test/xml/test_element_decl.rb +0 -73
- data/test/xml/test_entity_decl.rb +0 -122
- data/test/xml/test_entity_reference.rb +0 -262
- data/test/xml/test_namespace.rb +0 -96
- data/test/xml/test_node.rb +0 -1325
- data/test/xml/test_node_attributes.rb +0 -115
- data/test/xml/test_node_encoding.rb +0 -75
- data/test/xml/test_node_inheritance.rb +0 -32
- data/test/xml/test_node_reparenting.rb +0 -592
- data/test/xml/test_node_set.rb +0 -809
- data/test/xml/test_parse_options.rb +0 -64
- data/test/xml/test_processing_instruction.rb +0 -30
- data/test/xml/test_reader.rb +0 -620
- data/test/xml/test_reader_encoding.rb +0 -134
- data/test/xml/test_relax_ng.rb +0 -60
- data/test/xml/test_schema.rb +0 -142
- data/test/xml/test_syntax_error.rb +0 -36
- data/test/xml/test_text.rb +0 -60
- data/test/xml/test_unparented_node.rb +0 -483
- data/test/xml/test_xinclude.rb +0 -83
- data/test/xml/test_xpath.rb +0 -470
- data/test/xslt/test_custom_functions.rb +0 -133
- data/test/xslt/test_exception_handling.rb +0 -37
data/test/xml/test_document.rb
DELETED
@@ -1,982 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
require 'uri'
|
4
|
-
|
5
|
-
module Nokogiri
|
6
|
-
module XML
|
7
|
-
class TestDocument < Nokogiri::TestCase
|
8
|
-
URI = if URI.const_defined?(:DEFAULT_PARSER)
|
9
|
-
::URI::DEFAULT_PARSER
|
10
|
-
else
|
11
|
-
::URI
|
12
|
-
end
|
13
|
-
|
14
|
-
def setup
|
15
|
-
super
|
16
|
-
@xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_dtd_with_empty_internal_subset
|
20
|
-
doc = Nokogiri::XML <<-eoxml
|
21
|
-
<?xml version="1.0"?>
|
22
|
-
<!DOCTYPE people >
|
23
|
-
<people>
|
24
|
-
</people>
|
25
|
-
eoxml
|
26
|
-
assert doc.root
|
27
|
-
end
|
28
|
-
|
29
|
-
# issue #1005
|
30
|
-
def test_strict_parsing_empty_doc_should_raise_exception
|
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
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# issue #838
|
42
|
-
def test_document_with_invalid_prolog
|
43
|
-
doc = Nokogiri::XML '<? ?>'
|
44
|
-
assert_empty doc.content
|
45
|
-
end
|
46
|
-
|
47
|
-
# issue #837
|
48
|
-
def test_document_with_refentity
|
49
|
-
doc = Nokogiri::XML '&'
|
50
|
-
assert_equal '', doc.content
|
51
|
-
end
|
52
|
-
|
53
|
-
# issue #835
|
54
|
-
def test_manually_adding_reference_entities
|
55
|
-
d = Nokogiri::XML::Document.new
|
56
|
-
root = Nokogiri::XML::Element.new('bar', d)
|
57
|
-
txt = Nokogiri::XML::Text.new('foo', d)
|
58
|
-
ent = Nokogiri::XML::EntityReference.new(d, '#8217')
|
59
|
-
root << txt
|
60
|
-
root << ent
|
61
|
-
d << root
|
62
|
-
assert_match(/’/, d.to_html)
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_document_with_initial_space
|
66
|
-
doc = Nokogiri::XML(" <?xml version='1.0' encoding='utf-8' ?><first \>")
|
67
|
-
assert_equal 2, doc.children.size
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_root_set_to_nil
|
71
|
-
@xml.root = nil
|
72
|
-
assert_nil @xml.root
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_million_laugh_attach
|
76
|
-
doc = Nokogiri::XML '<?xml version="1.0"?>
|
77
|
-
<!DOCTYPE lolz [
|
78
|
-
<!ENTITY lol "lol">
|
79
|
-
<!ENTITY lol2 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
|
80
|
-
<!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">
|
81
|
-
<!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;">
|
82
|
-
<!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;">
|
83
|
-
<!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;">
|
84
|
-
<!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;">
|
85
|
-
<!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;">
|
86
|
-
<!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;">
|
87
|
-
]>
|
88
|
-
<lolz>&lol9;</lolz>'
|
89
|
-
assert_not_nil doc
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_million_laugh_attach_2
|
93
|
-
doc = Nokogiri::XML '<?xml version="1.0" encoding="UTF-8"?>
|
94
|
-
<!DOCTYPE member [
|
95
|
-
<!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
|
96
|
-
<!ENTITY b "&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;">
|
97
|
-
<!ENTITY c "&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;">
|
98
|
-
<!ENTITY d "&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;">
|
99
|
-
<!ENTITY e "&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;">
|
100
|
-
<!ENTITY f "&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;">
|
101
|
-
<!ENTITY g "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
|
102
|
-
]>
|
103
|
-
<member>
|
104
|
-
&a;
|
105
|
-
</member>'
|
106
|
-
assert_not_nil doc
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_ignore_unknown_namespace
|
110
|
-
doc = Nokogiri::XML(<<-eoxml)
|
111
|
-
<xml>
|
112
|
-
<unknown:foo xmlns='http://hello.com/' />
|
113
|
-
<bar />
|
114
|
-
</xml>
|
115
|
-
eoxml
|
116
|
-
if Nokogiri.jruby?
|
117
|
-
refute doc.xpath('//foo').first.namespace # assert that the namespace is nil
|
118
|
-
end
|
119
|
-
refute_empty doc.xpath('//bar'), "bar wasn't found in the document" # bar should be part of the doc
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_collect_namespaces
|
123
|
-
doc = Nokogiri::XML(<<-eoxml)
|
124
|
-
<xml>
|
125
|
-
<foo xmlns='hello'>
|
126
|
-
<bar xmlns:foo='world' />
|
127
|
-
</foo>
|
128
|
-
</xml>
|
129
|
-
eoxml
|
130
|
-
assert_equal({"xmlns"=>"hello", "xmlns:foo"=>"world"},
|
131
|
-
doc.collect_namespaces)
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_subclass_initialize_modify # testing a segv
|
135
|
-
Class.new(Nokogiri::XML::Document) {
|
136
|
-
def initialize
|
137
|
-
super
|
138
|
-
body_node = Nokogiri::XML::Node.new "body", self
|
139
|
-
body_node.content = "stuff"
|
140
|
-
self.root = body_node
|
141
|
-
end
|
142
|
-
}.new
|
143
|
-
end
|
144
|
-
|
145
|
-
def test_create_text_node
|
146
|
-
txt = @xml.create_text_node 'foo'
|
147
|
-
assert_instance_of Nokogiri::XML::Text, txt
|
148
|
-
assert_equal 'foo', txt.text
|
149
|
-
assert_equal @xml, txt.document
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_create_text_node_with_block
|
153
|
-
@xml.create_text_node 'foo' do |txt|
|
154
|
-
assert_instance_of Nokogiri::XML::Text, txt
|
155
|
-
assert_equal 'foo', txt.text
|
156
|
-
assert_equal @xml, txt.document
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
def test_create_element
|
161
|
-
elm = @xml.create_element('foo')
|
162
|
-
assert_instance_of Nokogiri::XML::Element, elm
|
163
|
-
assert_equal 'foo', elm.name
|
164
|
-
assert_equal @xml, elm.document
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_create_element_with_block
|
168
|
-
@xml.create_element('foo') do |elm|
|
169
|
-
assert_instance_of Nokogiri::XML::Element, elm
|
170
|
-
assert_equal 'foo', elm.name
|
171
|
-
assert_equal @xml, elm.document
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_create_element_with_attributes
|
176
|
-
elm = @xml.create_element('foo',:a => "1")
|
177
|
-
assert_instance_of Nokogiri::XML::Element, elm
|
178
|
-
assert_instance_of Nokogiri::XML::Attr, elm.attributes["a"]
|
179
|
-
assert_equal "1", elm["a"]
|
180
|
-
end
|
181
|
-
|
182
|
-
def test_create_element_with_namespace
|
183
|
-
elm = @xml.create_element('foo',:'xmlns:foo' => 'http://tenderlovemaking.com')
|
184
|
-
assert_equal 'http://tenderlovemaking.com', elm.namespaces['xmlns:foo']
|
185
|
-
end
|
186
|
-
|
187
|
-
def test_create_element_with_hyphenated_namespace
|
188
|
-
elm = @xml.create_element('foo',:'xmlns:SOAP-ENC' => 'http://tenderlovemaking.com')
|
189
|
-
assert_equal 'http://tenderlovemaking.com', elm.namespaces['xmlns:SOAP-ENC']
|
190
|
-
end
|
191
|
-
|
192
|
-
def test_create_element_with_content
|
193
|
-
elm = @xml.create_element('foo',"needs more xml/violence")
|
194
|
-
assert_equal "needs more xml/violence", elm.content
|
195
|
-
end
|
196
|
-
|
197
|
-
def test_create_cdata
|
198
|
-
cdata = @xml.create_cdata("abc")
|
199
|
-
assert_instance_of Nokogiri::XML::CDATA, cdata
|
200
|
-
assert_equal "abc", cdata.content
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_create_cdata_with_block
|
204
|
-
@xml.create_cdata("abc") do |cdata|
|
205
|
-
assert_instance_of Nokogiri::XML::CDATA, cdata
|
206
|
-
assert_equal "abc", cdata.content
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
def test_create_comment
|
211
|
-
comment = @xml.create_comment("abc")
|
212
|
-
assert_instance_of Nokogiri::XML::Comment, comment
|
213
|
-
assert_equal "abc", comment.content
|
214
|
-
end
|
215
|
-
|
216
|
-
def test_create_comment_with_block
|
217
|
-
@xml.create_comment("abc") do |comment|
|
218
|
-
assert_instance_of Nokogiri::XML::Comment, comment
|
219
|
-
assert_equal "abc", comment.content
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
def test_pp
|
224
|
-
out = StringIO.new(String.new)
|
225
|
-
::PP.pp @xml, out
|
226
|
-
assert_operator out.string.length, :>, 0
|
227
|
-
end
|
228
|
-
|
229
|
-
def test_create_internal_subset_on_existing_subset
|
230
|
-
assert_not_nil @xml.internal_subset
|
231
|
-
assert_raises(RuntimeError) do
|
232
|
-
@xml.create_internal_subset('staff', nil, 'staff.dtd')
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
def test_create_internal_subset
|
237
|
-
xml = Nokogiri::XML('<root />')
|
238
|
-
assert_nil xml.internal_subset
|
239
|
-
|
240
|
-
xml.create_internal_subset('name', nil, 'staff.dtd')
|
241
|
-
ss = xml.internal_subset
|
242
|
-
assert_equal 'name', ss.name
|
243
|
-
assert_nil ss.external_id
|
244
|
-
assert_equal 'staff.dtd', ss.system_id
|
245
|
-
end
|
246
|
-
|
247
|
-
def test_external_subset
|
248
|
-
assert_nil @xml.external_subset
|
249
|
-
Dir.chdir(ASSETS_DIR) do
|
250
|
-
@xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) { |cfg|
|
251
|
-
cfg.dtdload
|
252
|
-
}
|
253
|
-
end
|
254
|
-
assert @xml.external_subset
|
255
|
-
end
|
256
|
-
|
257
|
-
def test_create_external_subset_fails_with_existing_subset
|
258
|
-
assert_nil @xml.external_subset
|
259
|
-
Dir.chdir(ASSETS_DIR) do
|
260
|
-
@xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) { |cfg|
|
261
|
-
cfg.dtdload
|
262
|
-
}
|
263
|
-
end
|
264
|
-
assert @xml.external_subset
|
265
|
-
|
266
|
-
assert_raises(RuntimeError) do
|
267
|
-
@xml.create_external_subset('staff', nil, 'staff.dtd')
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
def test_create_external_subset
|
272
|
-
dtd = @xml.create_external_subset('staff', nil, 'staff.dtd')
|
273
|
-
assert_nil dtd.external_id
|
274
|
-
assert_equal 'staff.dtd', dtd.system_id
|
275
|
-
assert_equal 'staff', dtd.name
|
276
|
-
assert_equal dtd, @xml.external_subset
|
277
|
-
end
|
278
|
-
|
279
|
-
def test_version
|
280
|
-
assert_equal '1.0', @xml.version
|
281
|
-
end
|
282
|
-
|
283
|
-
def test_add_namespace
|
284
|
-
assert_raise NoMethodError do
|
285
|
-
@xml.add_namespace('foo', 'bar')
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
def test_attributes
|
290
|
-
assert_raise NoMethodError do
|
291
|
-
@xml.attributes
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
def test_namespace
|
296
|
-
assert_raise NoMethodError do
|
297
|
-
@xml.namespace
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
def test_namespace_definitions
|
302
|
-
assert_raise NoMethodError do
|
303
|
-
@xml.namespace_definitions
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
def test_line
|
308
|
-
assert_raise NoMethodError do
|
309
|
-
@xml.line
|
310
|
-
end
|
311
|
-
end
|
312
|
-
|
313
|
-
def test_empty_node_converted_to_html_is_not_self_closing
|
314
|
-
doc = Nokogiri::XML('<a></a>')
|
315
|
-
assert_equal "<a></a>", doc.inner_html
|
316
|
-
end
|
317
|
-
|
318
|
-
def test_fragment
|
319
|
-
fragment = @xml.fragment
|
320
|
-
assert_equal 0, fragment.children.length
|
321
|
-
end
|
322
|
-
|
323
|
-
def test_add_child_fragment_with_single_node
|
324
|
-
doc = Nokogiri::XML::Document.new
|
325
|
-
fragment = doc.fragment('<hello />')
|
326
|
-
doc.add_child fragment
|
327
|
-
assert_equal '/hello', doc.at('//hello').path
|
328
|
-
assert_equal 'hello', doc.root.name
|
329
|
-
end
|
330
|
-
|
331
|
-
def test_add_child_fragment_with_multiple_nodes
|
332
|
-
doc = Nokogiri::XML::Document.new
|
333
|
-
fragment = doc.fragment('<hello /><goodbye />')
|
334
|
-
assert_raises(RuntimeError) do
|
335
|
-
doc.add_child fragment
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
def test_add_child_with_multiple_roots
|
340
|
-
assert_raises(RuntimeError) do
|
341
|
-
@xml << Node.new('foo', @xml)
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
def test_add_child_with_string
|
346
|
-
doc = Nokogiri::XML::Document.new
|
347
|
-
doc.add_child "<div>quack!</div>"
|
348
|
-
assert_equal 1, doc.root.children.length
|
349
|
-
assert_equal "quack!", doc.root.children.first.content
|
350
|
-
end
|
351
|
-
|
352
|
-
def test_prepend
|
353
|
-
doc = Nokogiri::XML('<root>')
|
354
|
-
|
355
|
-
node_set = doc.root.prepend_child '<branch/>'
|
356
|
-
assert_equal %w[branch], node_set.map(&:name)
|
357
|
-
|
358
|
-
branch = doc.at('//branch')
|
359
|
-
|
360
|
-
leaves = %w[leaf1 leaf2 leaf3]
|
361
|
-
leaves.each { |name|
|
362
|
-
branch.prepend_child('<%s/>' % name)
|
363
|
-
}
|
364
|
-
assert_equal leaves.length, branch.children.length
|
365
|
-
assert_equal leaves.reverse, branch.children.map(&:name)
|
366
|
-
end
|
367
|
-
|
368
|
-
def test_prepend_child_fragment_with_single_node
|
369
|
-
doc = Nokogiri::XML::Document.new
|
370
|
-
fragment = doc.fragment('<hello />')
|
371
|
-
doc.prepend_child fragment
|
372
|
-
assert_equal '/hello', doc.at('//hello').path
|
373
|
-
assert_equal 'hello', doc.root.name
|
374
|
-
end
|
375
|
-
|
376
|
-
def test_prepend_child_fragment_with_multiple_nodes
|
377
|
-
doc = Nokogiri::XML::Document.new
|
378
|
-
fragment = doc.fragment('<hello /><goodbye />')
|
379
|
-
assert_raises(RuntimeError) do
|
380
|
-
doc.prepend_child fragment
|
381
|
-
end
|
382
|
-
end
|
383
|
-
|
384
|
-
def test_prepend_child_with_multiple_roots
|
385
|
-
assert_raises(RuntimeError) do
|
386
|
-
@xml.prepend_child Node.new('foo', @xml)
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
|
-
def test_prepend_child_with_string
|
391
|
-
doc = Nokogiri::XML::Document.new
|
392
|
-
doc.prepend_child "<div>quack!</div>"
|
393
|
-
assert_equal 1, doc.root.children.length
|
394
|
-
assert_equal "quack!", doc.root.children.first.content
|
395
|
-
end
|
396
|
-
|
397
|
-
def test_move_root_to_document_with_no_root
|
398
|
-
sender = Nokogiri::XML('<root>foo</root>')
|
399
|
-
newdoc = Nokogiri::XML::Document.new
|
400
|
-
newdoc.root = sender.root
|
401
|
-
end
|
402
|
-
|
403
|
-
def test_move_root_with_existing_root_gets_gcd
|
404
|
-
doc = Nokogiri::XML('<root>test</root>')
|
405
|
-
doc2 = Nokogiri::XML("<root>#{'x' * 5000000}</root>")
|
406
|
-
doc2.root = doc.root
|
407
|
-
end
|
408
|
-
|
409
|
-
def test_validate
|
410
|
-
if Nokogiri.uses_libxml?
|
411
|
-
assert_equal 44, @xml.validate.length
|
412
|
-
else
|
413
|
-
xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) {|cfg| cfg.dtdvalid}
|
414
|
-
assert_equal 40, xml.validate.length
|
415
|
-
end
|
416
|
-
end
|
417
|
-
|
418
|
-
def test_validate_no_internal_subset
|
419
|
-
doc = Nokogiri::XML('<test/>')
|
420
|
-
assert_nil doc.validate
|
421
|
-
end
|
422
|
-
|
423
|
-
def test_clone
|
424
|
-
assert @xml.clone
|
425
|
-
end
|
426
|
-
|
427
|
-
def test_document_should_not_have_default_ns
|
428
|
-
doc = Nokogiri::XML::Document.new
|
429
|
-
|
430
|
-
assert_raises NoMethodError do
|
431
|
-
doc.default_namespace = 'http://innernet.com/'
|
432
|
-
end
|
433
|
-
|
434
|
-
assert_raises NoMethodError do
|
435
|
-
doc.add_namespace_definition('foo', 'bar')
|
436
|
-
end
|
437
|
-
end
|
438
|
-
|
439
|
-
def test_parse_handles_nil_gracefully
|
440
|
-
@doc = Nokogiri::XML::Document.parse(nil)
|
441
|
-
assert_instance_of Nokogiri::XML::Document, @doc
|
442
|
-
end
|
443
|
-
|
444
|
-
def test_parse_takes_block
|
445
|
-
options = nil
|
446
|
-
Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) do |cfg|
|
447
|
-
options = cfg
|
448
|
-
end
|
449
|
-
assert options
|
450
|
-
end
|
451
|
-
|
452
|
-
def test_parse_yields_parse_options
|
453
|
-
options = nil
|
454
|
-
Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) do |cfg|
|
455
|
-
options = cfg
|
456
|
-
options.nonet.nowarning.dtdattr
|
457
|
-
end
|
458
|
-
assert options.nonet?
|
459
|
-
assert options.nowarning?
|
460
|
-
assert options.dtdattr?
|
461
|
-
end
|
462
|
-
|
463
|
-
def test_XML_takes_block
|
464
|
-
options = nil
|
465
|
-
Nokogiri::XML(File.read(XML_FILE), XML_FILE) do |cfg|
|
466
|
-
options = cfg
|
467
|
-
options.nonet.nowarning.dtdattr
|
468
|
-
end
|
469
|
-
assert options.nonet?
|
470
|
-
assert options.nowarning?
|
471
|
-
assert options.dtdattr?
|
472
|
-
end
|
473
|
-
|
474
|
-
def test_subclass
|
475
|
-
klass = Class.new(Nokogiri::XML::Document)
|
476
|
-
doc = klass.new
|
477
|
-
assert_instance_of klass, doc
|
478
|
-
end
|
479
|
-
|
480
|
-
def test_subclass_initialize
|
481
|
-
klass = Class.new(Nokogiri::XML::Document) do
|
482
|
-
attr_accessor :initialized_with
|
483
|
-
|
484
|
-
def initialize(*args)
|
485
|
-
@initialized_with = args
|
486
|
-
end
|
487
|
-
end
|
488
|
-
doc = klass.new("1.0", 1)
|
489
|
-
assert_equal ["1.0", 1], doc.initialized_with
|
490
|
-
end
|
491
|
-
|
492
|
-
def test_subclass_dup
|
493
|
-
klass = Class.new(Nokogiri::XML::Document)
|
494
|
-
doc = klass.new.dup
|
495
|
-
assert_instance_of klass, doc
|
496
|
-
end
|
497
|
-
|
498
|
-
def test_subclass_parse
|
499
|
-
klass = Class.new(Nokogiri::XML::Document)
|
500
|
-
doc = klass.parse(File.read(XML_FILE))
|
501
|
-
# lame hack uses root to avoid comparing DOCTYPE tags which can appear out of order.
|
502
|
-
# I should really finish lorax and use that here.
|
503
|
-
assert_equal @xml.root.to_s, doc.root.to_s
|
504
|
-
assert_instance_of klass, doc
|
505
|
-
end
|
506
|
-
|
507
|
-
def test_document_parse_method
|
508
|
-
xml = Nokogiri::XML::Document.parse(File.read(XML_FILE))
|
509
|
-
# lame hack uses root to avoid comparing DOCTYPE tags which can appear out of order.
|
510
|
-
# I should really finish lorax and use that here.
|
511
|
-
assert_equal @xml.root.to_s, xml.root.to_s
|
512
|
-
end
|
513
|
-
|
514
|
-
def test_encoding=
|
515
|
-
@xml.encoding = 'UTF-8'
|
516
|
-
assert_match 'UTF-8', @xml.to_xml
|
517
|
-
|
518
|
-
@xml.encoding = 'EUC-JP'
|
519
|
-
assert_match 'EUC-JP', @xml.to_xml
|
520
|
-
end
|
521
|
-
|
522
|
-
def test_namespace_should_not_exist
|
523
|
-
assert_raises(NoMethodError) {
|
524
|
-
@xml.namespace
|
525
|
-
}
|
526
|
-
end
|
527
|
-
|
528
|
-
def test_non_existant_function
|
529
|
-
# WTF. I don't know why this is different between MRI and Jruby
|
530
|
-
# They should be the same... Either way, raising an exception
|
531
|
-
# is the correct thing to do.
|
532
|
-
exception = RuntimeError
|
533
|
-
|
534
|
-
if !Nokogiri.uses_libxml? || (Nokogiri.uses_libxml? && Nokogiri::VERSION_INFO['libxml']['platform'] == 'jruby')
|
535
|
-
exception = Nokogiri::XML::XPath::SyntaxError
|
536
|
-
end
|
537
|
-
|
538
|
-
assert_raises(exception) {
|
539
|
-
@xml.xpath('//name[foo()]')
|
540
|
-
}
|
541
|
-
end
|
542
|
-
|
543
|
-
def test_xpath_syntax_error
|
544
|
-
assert_raises(Nokogiri::XML::XPath::SyntaxError) do
|
545
|
-
@xml.xpath('\\')
|
546
|
-
end
|
547
|
-
end
|
548
|
-
|
549
|
-
def test_ancestors
|
550
|
-
assert_equal 0, @xml.ancestors.length
|
551
|
-
end
|
552
|
-
|
553
|
-
def test_root_node_parent_is_document
|
554
|
-
parent = @xml.root.parent
|
555
|
-
assert_equal @xml, parent
|
556
|
-
assert_instance_of Nokogiri::XML::Document, parent
|
557
|
-
end
|
558
|
-
|
559
|
-
def test_xmlns_is_automatically_registered
|
560
|
-
doc = Nokogiri::XML(<<-eoxml)
|
561
|
-
<root xmlns="http://tenderlovemaking.com/">
|
562
|
-
<foo>
|
563
|
-
bar
|
564
|
-
</foo>
|
565
|
-
</root>
|
566
|
-
eoxml
|
567
|
-
assert_equal 1, doc.css('xmlns|foo').length
|
568
|
-
assert_equal 1, doc.css('foo').length
|
569
|
-
assert_equal 0, doc.css('|foo').length
|
570
|
-
assert_equal 1, doc.xpath('//xmlns:foo').length
|
571
|
-
assert_equal 1, doc.search('xmlns|foo').length
|
572
|
-
assert_equal 1, doc.search('//xmlns:foo').length
|
573
|
-
assert doc.at('xmlns|foo')
|
574
|
-
assert doc.at('//xmlns:foo')
|
575
|
-
assert doc.at('foo')
|
576
|
-
end
|
577
|
-
|
578
|
-
def test_xmlns_is_registered_for_nodesets
|
579
|
-
doc = Nokogiri::XML(<<-eoxml)
|
580
|
-
<root xmlns="http://tenderlovemaking.com/">
|
581
|
-
<foo>
|
582
|
-
<bar>
|
583
|
-
baz
|
584
|
-
</bar>
|
585
|
-
</foo>
|
586
|
-
</root>
|
587
|
-
eoxml
|
588
|
-
assert_equal 1, doc.css('xmlns|foo').css('xmlns|bar').length
|
589
|
-
assert_equal 1, doc.css('foo').css('bar').length
|
590
|
-
assert_equal 1, doc.xpath('//xmlns:foo').xpath('./xmlns:bar').length
|
591
|
-
assert_equal 1, doc.search('xmlns|foo').search('xmlns|bar').length
|
592
|
-
assert_equal 1, doc.search('//xmlns:foo').search('./xmlns:bar').length
|
593
|
-
end
|
594
|
-
|
595
|
-
def test_to_xml_with_indent
|
596
|
-
doc = Nokogiri::XML('<root><foo><bar/></foo></root>')
|
597
|
-
doc = Nokogiri::XML(doc.to_xml(:indent => 5))
|
598
|
-
|
599
|
-
assert_indent 5, doc
|
600
|
-
end
|
601
|
-
|
602
|
-
def test_write_xml_to_with_indent
|
603
|
-
io = StringIO.new
|
604
|
-
doc = Nokogiri::XML('<root><foo><bar/></foo></root>')
|
605
|
-
doc.write_xml_to io, :indent => 5
|
606
|
-
io.rewind
|
607
|
-
doc = Nokogiri::XML(io.read)
|
608
|
-
assert_indent 5, doc
|
609
|
-
end
|
610
|
-
|
611
|
-
# wtf... osx's libxml sucks.
|
612
|
-
unless !Nokogiri.uses_libxml? || Nokogiri::LIBXML_VERSION =~ /^2\.6\./
|
613
|
-
def test_encoding
|
614
|
-
xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE, 'UTF-8')
|
615
|
-
assert_equal 'UTF-8', xml.encoding
|
616
|
-
end
|
617
|
-
end
|
618
|
-
|
619
|
-
def test_memory_explosion_on_invalid_xml
|
620
|
-
doc = Nokogiri::XML("<<<")
|
621
|
-
refute_nil doc
|
622
|
-
refute_empty doc.errors
|
623
|
-
end
|
624
|
-
|
625
|
-
def test_memory_explosion_on_wrong_formatted_element_following_the_root_element
|
626
|
-
doc = Nokogiri::XML("<a/><\n")
|
627
|
-
refute_nil doc
|
628
|
-
refute_empty doc.errors
|
629
|
-
end
|
630
|
-
|
631
|
-
def test_document_has_errors
|
632
|
-
doc = Nokogiri::XML(<<-eoxml)
|
633
|
-
<foo><bar></foo>
|
634
|
-
eoxml
|
635
|
-
assert doc.errors.length > 0
|
636
|
-
doc.errors.each do |error|
|
637
|
-
assert_match error.message, error.inspect
|
638
|
-
assert_match error.message, error.to_s
|
639
|
-
end
|
640
|
-
end
|
641
|
-
|
642
|
-
def test_strict_document_throws_syntax_error
|
643
|
-
assert_raises(Nokogiri::XML::SyntaxError) {
|
644
|
-
Nokogiri::XML('<foo><bar></foo>', nil, nil, 0)
|
645
|
-
}
|
646
|
-
|
647
|
-
assert_raises(Nokogiri::XML::SyntaxError) {
|
648
|
-
Nokogiri::XML('<foo><bar></foo>') { |cfg|
|
649
|
-
cfg.strict
|
650
|
-
}
|
651
|
-
}
|
652
|
-
|
653
|
-
assert_raises(Nokogiri::XML::SyntaxError) {
|
654
|
-
Nokogiri::XML(StringIO.new('<foo><bar></foo>')) { |cfg|
|
655
|
-
cfg.strict
|
656
|
-
}
|
657
|
-
}
|
658
|
-
end
|
659
|
-
|
660
|
-
def test_XML_function
|
661
|
-
xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
|
662
|
-
assert xml.xml?
|
663
|
-
end
|
664
|
-
|
665
|
-
def test_url
|
666
|
-
assert @xml.url
|
667
|
-
assert_equal XML_FILE, URI.unescape(@xml.url).sub('file:///', '')
|
668
|
-
end
|
669
|
-
|
670
|
-
def test_document_parent
|
671
|
-
xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
|
672
|
-
assert_raises(NoMethodError) {
|
673
|
-
xml.parent
|
674
|
-
}
|
675
|
-
end
|
676
|
-
|
677
|
-
def test_document_name
|
678
|
-
xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
|
679
|
-
assert_equal 'document', xml.name
|
680
|
-
end
|
681
|
-
|
682
|
-
def test_parse_can_take_io
|
683
|
-
xml = nil
|
684
|
-
File.open(XML_FILE, 'rb') { |f|
|
685
|
-
xml = Nokogiri::XML(f)
|
686
|
-
}
|
687
|
-
assert xml.xml?
|
688
|
-
set = xml.search('//employee')
|
689
|
-
assert set.length > 0
|
690
|
-
end
|
691
|
-
|
692
|
-
def test_parsing_empty_io
|
693
|
-
doc = Nokogiri::XML.parse(StringIO.new(''))
|
694
|
-
refute_nil doc
|
695
|
-
end
|
696
|
-
|
697
|
-
def test_parse_works_with_an_object_that_responds_to_read
|
698
|
-
klass = Class.new do
|
699
|
-
def read *args
|
700
|
-
"<div>foo</div>"
|
701
|
-
end
|
702
|
-
end
|
703
|
-
|
704
|
-
doc = Nokogiri::XML.parse klass.new
|
705
|
-
doc.at_css("div").content.must_equal("foo")
|
706
|
-
end
|
707
|
-
|
708
|
-
def test_search_on_empty_documents
|
709
|
-
doc = Nokogiri::XML::Document.new
|
710
|
-
ns = doc.search('//foo')
|
711
|
-
assert_equal 0, ns.length
|
712
|
-
|
713
|
-
ns = doc.css('foo')
|
714
|
-
assert_equal 0, ns.length
|
715
|
-
|
716
|
-
ns = doc.xpath('//foo')
|
717
|
-
assert_equal 0, ns.length
|
718
|
-
end
|
719
|
-
|
720
|
-
def test_document_search_with_multiple_queries
|
721
|
-
xml = '<document>
|
722
|
-
<thing>
|
723
|
-
<div class="title">important thing</div>
|
724
|
-
</thing>
|
725
|
-
<thing>
|
726
|
-
<div class="content">stuff</div>
|
727
|
-
</thing>
|
728
|
-
<thing>
|
729
|
-
<p class="blah">more stuff</div>
|
730
|
-
</thing>
|
731
|
-
</document>'
|
732
|
-
document = Nokogiri::XML(xml)
|
733
|
-
assert_kind_of Nokogiri::XML::Document, document
|
734
|
-
|
735
|
-
assert_equal 3, document.xpath('.//div', './/p').length
|
736
|
-
assert_equal 3, document.css('.title', '.content', 'p').length
|
737
|
-
assert_equal 3, document.search('.//div', 'p.blah').length
|
738
|
-
end
|
739
|
-
|
740
|
-
def test_bad_xpath_raises_syntax_error
|
741
|
-
assert_raises(XML::XPath::SyntaxError) {
|
742
|
-
@xml.xpath('\\')
|
743
|
-
}
|
744
|
-
end
|
745
|
-
|
746
|
-
def test_find_with_namespace
|
747
|
-
doc = Nokogiri::XML.parse(<<-eoxml)
|
748
|
-
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
749
|
-
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
750
|
-
</x>
|
751
|
-
eoxml
|
752
|
-
|
753
|
-
ctx = Nokogiri::XML::XPathContext.new(doc)
|
754
|
-
ctx.register_ns 'tenderlove', 'http://tenderlovemaking.com/'
|
755
|
-
set = ctx.evaluate('//tenderlove:foo')
|
756
|
-
assert_equal 1, set.length
|
757
|
-
assert_equal 'foo', set.first.name
|
758
|
-
|
759
|
-
# It looks like only the URI is important:
|
760
|
-
ctx = Nokogiri::XML::XPathContext.new(doc)
|
761
|
-
ctx.register_ns 'america', 'http://tenderlovemaking.com/'
|
762
|
-
set = ctx.evaluate('//america:foo')
|
763
|
-
assert_equal 1, set.length
|
764
|
-
assert_equal 'foo', set.first.name
|
765
|
-
|
766
|
-
# Its so important that a missing slash will cause it to return nothing
|
767
|
-
ctx = Nokogiri::XML::XPathContext.new(doc)
|
768
|
-
ctx.register_ns 'america', 'http://tenderlovemaking.com'
|
769
|
-
set = ctx.evaluate('//america:foo')
|
770
|
-
assert_equal 0, set.length
|
771
|
-
end
|
772
|
-
|
773
|
-
def test_xml?
|
774
|
-
assert @xml.xml?
|
775
|
-
end
|
776
|
-
|
777
|
-
def test_document
|
778
|
-
assert @xml.document
|
779
|
-
end
|
780
|
-
|
781
|
-
def test_singleton_methods
|
782
|
-
assert node_set = @xml.search('//name')
|
783
|
-
assert node_set.length > 0
|
784
|
-
node = node_set.first
|
785
|
-
def node.test
|
786
|
-
'test'
|
787
|
-
end
|
788
|
-
assert node_set = @xml.search('//name')
|
789
|
-
assert_equal 'test', node_set.first.test
|
790
|
-
end
|
791
|
-
|
792
|
-
def test_multiple_search
|
793
|
-
assert node_set = @xml.search('//employee', '//name')
|
794
|
-
employees = @xml.search('//employee')
|
795
|
-
names = @xml.search('//name')
|
796
|
-
assert_equal(employees.length + names.length, node_set.length)
|
797
|
-
end
|
798
|
-
|
799
|
-
def test_node_set_index
|
800
|
-
assert node_set = @xml.search('//employee')
|
801
|
-
|
802
|
-
assert_equal(5, node_set.length)
|
803
|
-
assert node_set[4]
|
804
|
-
assert_nil node_set[5]
|
805
|
-
end
|
806
|
-
|
807
|
-
def test_search
|
808
|
-
assert node_set = @xml.search('//employee')
|
809
|
-
|
810
|
-
assert_equal(5, node_set.length)
|
811
|
-
|
812
|
-
node_set.each do |node|
|
813
|
-
assert_equal('employee', node.name)
|
814
|
-
end
|
815
|
-
end
|
816
|
-
|
817
|
-
def test_dump
|
818
|
-
assert @xml.serialize
|
819
|
-
assert @xml.to_xml
|
820
|
-
end
|
821
|
-
|
822
|
-
def test_dup
|
823
|
-
dup = @xml.dup
|
824
|
-
assert_instance_of Nokogiri::XML::Document, dup
|
825
|
-
assert dup.xml?, 'duplicate should be xml'
|
826
|
-
end
|
827
|
-
|
828
|
-
def test_new
|
829
|
-
doc = nil
|
830
|
-
doc = Nokogiri::XML::Document.new
|
831
|
-
assert doc
|
832
|
-
assert doc.xml?
|
833
|
-
assert_nil doc.root
|
834
|
-
end
|
835
|
-
|
836
|
-
def test_set_root
|
837
|
-
doc = nil
|
838
|
-
doc = Nokogiri::XML::Document.new
|
839
|
-
assert doc
|
840
|
-
assert doc.xml?
|
841
|
-
assert_nil doc.root
|
842
|
-
node = Nokogiri::XML::Node.new("b", doc) { |n|
|
843
|
-
n.content = 'hello world'
|
844
|
-
}
|
845
|
-
assert_equal('hello world', node.content)
|
846
|
-
doc.root = node
|
847
|
-
assert_equal(node, doc.root)
|
848
|
-
end
|
849
|
-
|
850
|
-
def test_remove_namespaces
|
851
|
-
doc = Nokogiri::XML <<-EOX
|
852
|
-
<root xmlns:a="http://a.flavorjon.es/" xmlns:b="http://b.flavorjon.es/">
|
853
|
-
<a:foo>hello from a</a:foo>
|
854
|
-
<b:foo>hello from b</b:foo>
|
855
|
-
<container xmlns:c="http://c.flavorjon.es/">
|
856
|
-
<c:foo c:attr='attr-value'>hello from c</c:foo>
|
857
|
-
</container>
|
858
|
-
</root>
|
859
|
-
EOX
|
860
|
-
|
861
|
-
namespaces = doc.root.namespaces
|
862
|
-
|
863
|
-
# assert on setup
|
864
|
-
assert_equal 2, doc.root.namespaces.length
|
865
|
-
assert_equal 3, doc.at_xpath("//container").namespaces.length
|
866
|
-
assert_equal 0, doc.xpath("//foo").length
|
867
|
-
assert_equal 1, doc.xpath("//a:foo").length
|
868
|
-
assert_equal 1, doc.xpath("//a:foo").length
|
869
|
-
assert_equal 1, doc.xpath("//x:foo", "x" => "http://c.flavorjon.es/").length
|
870
|
-
assert_match %r{foo c:attr}, doc.to_xml
|
871
|
-
doc.at_xpath("//x:foo", "x" => "http://c.flavorjon.es/").tap do |node|
|
872
|
-
assert_nil node["attr"]
|
873
|
-
assert_equal "attr-value", node["c:attr"]
|
874
|
-
assert_nil node.attribute_with_ns("attr", nil)
|
875
|
-
assert_equal "attr-value", node.attribute_with_ns("attr", "http://c.flavorjon.es/").value
|
876
|
-
assert_equal "attr-value", node.attributes["attr"].value
|
877
|
-
end
|
878
|
-
|
879
|
-
doc.remove_namespaces!
|
880
|
-
|
881
|
-
assert_equal 0, doc.root.namespaces.length
|
882
|
-
assert_equal 0, doc.at_xpath("//container").namespaces.length
|
883
|
-
assert_equal 3, doc.xpath("//foo").length
|
884
|
-
assert_equal 0, doc.xpath("//a:foo", namespaces).length
|
885
|
-
assert_equal 0, doc.xpath("//a:foo", namespaces).length
|
886
|
-
assert_equal 0, doc.xpath("//x:foo", "x" => "http://c.flavorjon.es/").length
|
887
|
-
assert_match %r{foo attr}, doc.to_xml
|
888
|
-
doc.at_xpath("//container/foo").tap do |node|
|
889
|
-
assert_equal "attr-value", node["attr"]
|
890
|
-
assert_nil node["c:attr"]
|
891
|
-
assert_equal "attr-value", node.attribute_with_ns("attr", nil).value
|
892
|
-
assert_nil node.attribute_with_ns("attr", "http://c.flavorjon.es/")
|
893
|
-
assert_equal "attr-value", node.attributes["attr"].value # doesn't change!
|
894
|
-
end
|
895
|
-
end
|
896
|
-
|
897
|
-
# issue #785
|
898
|
-
def test_attribute_decoration
|
899
|
-
decorator = Module.new do
|
900
|
-
def test_method
|
901
|
-
end
|
902
|
-
end
|
903
|
-
|
904
|
-
util_decorate(@xml, decorator)
|
905
|
-
|
906
|
-
assert @xml.search('//@street').first.respond_to?(:test_method)
|
907
|
-
end
|
908
|
-
|
909
|
-
def test_subset_is_decorated
|
910
|
-
x = Module.new do
|
911
|
-
def awesome!
|
912
|
-
end
|
913
|
-
end
|
914
|
-
util_decorate(@xml, x)
|
915
|
-
|
916
|
-
assert @xml.respond_to?(:awesome!)
|
917
|
-
assert node_set = @xml.search('//staff')
|
918
|
-
assert node_set.respond_to?(:awesome!)
|
919
|
-
assert subset = node_set.search('.//employee')
|
920
|
-
assert subset.respond_to?(:awesome!)
|
921
|
-
assert sub_subset = node_set.search('.//name')
|
922
|
-
assert sub_subset.respond_to?(:awesome!)
|
923
|
-
end
|
924
|
-
|
925
|
-
def test_decorator_is_applied
|
926
|
-
x = Module.new do
|
927
|
-
def awesome!
|
928
|
-
end
|
929
|
-
end
|
930
|
-
util_decorate(@xml, x)
|
931
|
-
|
932
|
-
assert @xml.respond_to?(:awesome!)
|
933
|
-
assert node_set = @xml.search('//employee')
|
934
|
-
assert node_set.respond_to?(:awesome!)
|
935
|
-
node_set.each do |node|
|
936
|
-
assert node.respond_to?(:awesome!), node.class
|
937
|
-
end
|
938
|
-
assert @xml.root.respond_to?(:awesome!)
|
939
|
-
assert @xml.children.respond_to?(:awesome!)
|
940
|
-
end
|
941
|
-
|
942
|
-
if Nokogiri.jruby?
|
943
|
-
def wrap_java_document
|
944
|
-
require 'java'
|
945
|
-
factory = javax.xml.parsers.DocumentBuilderFactory.newInstance
|
946
|
-
builder = factory.newDocumentBuilder
|
947
|
-
document = builder.newDocument
|
948
|
-
root = document.createElement("foo")
|
949
|
-
document.appendChild(root)
|
950
|
-
Nokogiri::XML::Document.wrap(document)
|
951
|
-
end
|
952
|
-
end
|
953
|
-
|
954
|
-
def test_java_integration
|
955
|
-
skip("Ruby doesn't have the wrap method") unless Nokogiri.jruby?
|
956
|
-
noko_doc = wrap_java_document
|
957
|
-
assert_equal 'foo', noko_doc.root.name
|
958
|
-
|
959
|
-
noko_doc = Nokogiri::XML(<<eoxml)
|
960
|
-
<foo xmlns='hello'>
|
961
|
-
<bar xmlns:foo='world' />
|
962
|
-
</foo>
|
963
|
-
eoxml
|
964
|
-
dom = noko_doc.to_java
|
965
|
-
assert dom.kind_of? org.w3c.dom.Document
|
966
|
-
assert_equal 'foo', dom.getDocumentElement().getTagName()
|
967
|
-
end
|
968
|
-
|
969
|
-
def test_add_child
|
970
|
-
skip("Ruby doesn't have the wrap method") unless Nokogiri.jruby?
|
971
|
-
doc = wrap_java_document
|
972
|
-
doc.root.add_child "<bar />"
|
973
|
-
end
|
974
|
-
|
975
|
-
def test_can_be_closed
|
976
|
-
f = File.open XML_FILE
|
977
|
-
Nokogiri::XML f
|
978
|
-
f.close
|
979
|
-
end
|
980
|
-
end
|
981
|
-
end
|
982
|
-
end
|