nokogiri 1.4.3.1-java → 1.5.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gemtest +0 -0
- data/CHANGELOG.ja.rdoc +113 -0
- data/CHANGELOG.rdoc +113 -1
- data/Manifest.txt +72 -68
- data/README.ja.rdoc +4 -4
- data/README.rdoc +31 -7
- data/Rakefile +110 -132
- data/bin/nokogiri +7 -3
- data/ext/java/nokogiri/EncodingHandler.java +124 -0
- data/ext/java/nokogiri/HtmlDocument.java +119 -0
- data/ext/java/nokogiri/HtmlElementDescription.java +145 -0
- data/ext/java/nokogiri/HtmlEntityLookup.java +79 -0
- data/ext/java/nokogiri/HtmlSaxParserContext.java +259 -0
- data/ext/java/nokogiri/NokogiriService.java +590 -0
- data/ext/java/nokogiri/XmlAttr.java +180 -0
- data/ext/java/nokogiri/XmlAttributeDecl.java +130 -0
- data/ext/java/nokogiri/XmlCdata.java +84 -0
- data/ext/java/nokogiri/XmlComment.java +86 -0
- data/ext/java/nokogiri/XmlDocument.java +519 -0
- data/ext/java/nokogiri/XmlDocumentFragment.java +223 -0
- data/ext/java/nokogiri/XmlDtd.java +469 -0
- data/ext/java/nokogiri/XmlElement.java +195 -0
- data/ext/java/nokogiri/XmlElementContent.java +382 -0
- data/ext/java/nokogiri/XmlElementDecl.java +152 -0
- data/ext/java/nokogiri/XmlEntityDecl.java +162 -0
- data/ext/java/nokogiri/XmlEntityReference.java +97 -0
- data/ext/java/nokogiri/XmlNamespace.java +183 -0
- data/ext/java/nokogiri/XmlNode.java +1378 -0
- data/ext/java/nokogiri/XmlNodeSet.java +267 -0
- data/ext/java/nokogiri/XmlProcessingInstruction.java +99 -0
- data/ext/java/nokogiri/XmlReader.java +408 -0
- data/ext/java/nokogiri/XmlRelaxng.java +144 -0
- data/ext/java/nokogiri/XmlSaxParserContext.java +367 -0
- data/ext/java/nokogiri/XmlSaxPushParser.java +184 -0
- data/ext/java/nokogiri/XmlSchema.java +324 -0
- data/ext/java/nokogiri/XmlSyntaxError.java +119 -0
- data/ext/java/nokogiri/XmlText.java +119 -0
- data/ext/java/nokogiri/XmlXpathContext.java +199 -0
- data/ext/java/nokogiri/XsltStylesheet.java +197 -0
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +204 -0
- data/ext/java/nokogiri/internals/NokogiriDocumentCache.java +73 -0
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +86 -0
- data/ext/java/nokogiri/internals/NokogiriHandler.java +327 -0
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +639 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +167 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +130 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +74 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +121 -0
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +79 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +141 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +73 -0
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +67 -0
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +86 -0
- data/ext/java/nokogiri/internals/ParserContext.java +276 -0
- data/ext/java/nokogiri/internals/PushInputStream.java +411 -0
- data/ext/java/nokogiri/internals/ReaderNode.java +531 -0
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +567 -0
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +76 -0
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +42 -0
- data/ext/java/nokogiri/internals/XmlDomParser.java +76 -0
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +244 -0
- data/ext/java/nokogiri/internals/XmlSaxParser.java +65 -0
- data/ext/java/nokogiri/internals/XsltExtensionFunction.java +72 -0
- data/ext/nokogiri/depend +358 -32
- data/ext/nokogiri/extconf.rb +10 -6
- data/ext/nokogiri/nokogiri.c +23 -3
- data/ext/nokogiri/nokogiri.h +7 -2
- data/ext/nokogiri/xml_document.c +9 -0
- data/ext/nokogiri/xml_dtd.c +2 -2
- data/ext/nokogiri/xml_io.c +32 -7
- data/ext/nokogiri/xml_node.c +45 -25
- data/ext/nokogiri/xml_node_set.c +1 -1
- data/ext/nokogiri/xml_relax_ng.c +0 -7
- data/ext/nokogiri/xml_sax_parser.c +14 -7
- data/ext/nokogiri/xml_sax_parser_context.c +40 -0
- data/ext/nokogiri/xml_xpath_context.c +33 -2
- data/ext/nokogiri/xslt_stylesheet.c +128 -6
- data/lib/isorelax.jar +0 -0
- data/lib/jing.jar +0 -0
- data/lib/nekodtd.jar +0 -0
- data/lib/nekohtml.jar +0 -0
- data/lib/nokogiri/css/parser.rb +665 -70
- data/lib/nokogiri/css/parser.y +3 -1
- data/lib/nokogiri/css/parser_extras.rb +91 -0
- data/lib/nokogiri/css/tokenizer.rb +148 -3
- data/lib/nokogiri/css/tokenizer.rex +1 -1
- data/lib/nokogiri/css/xpath_visitor.rb +15 -7
- data/lib/nokogiri/css.rb +5 -3
- data/lib/nokogiri/decorators/slop.rb +5 -3
- data/lib/nokogiri/html/document.rb +142 -19
- data/lib/nokogiri/html/document_fragment.rb +19 -17
- data/lib/nokogiri/html/element_description_defaults.rb +671 -0
- data/lib/nokogiri/html/sax/parser.rb +6 -2
- data/lib/nokogiri/html.rb +1 -0
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version.rb +76 -26
- data/lib/nokogiri/xml/attribute_decl.rb +1 -1
- data/lib/nokogiri/xml/builder.rb +7 -0
- data/lib/nokogiri/xml/document.rb +43 -2
- data/lib/nokogiri/xml/document_fragment.rb +16 -2
- data/lib/nokogiri/xml/dtd.rb +12 -1
- data/lib/nokogiri/xml/element_decl.rb +1 -1
- data/lib/nokogiri/xml/entity_decl.rb +1 -1
- data/lib/nokogiri/xml/node/save_options.rb +20 -1
- data/lib/nokogiri/xml/node.rb +198 -78
- data/lib/nokogiri/xml/node_set.rb +10 -3
- data/lib/nokogiri/xml/parse_options.rb +8 -0
- data/lib/nokogiri/xml/reader.rb +42 -6
- data/lib/nokogiri/xml/sax/document.rb +4 -2
- data/lib/nokogiri/xml/schema.rb +7 -1
- data/lib/nokogiri/xslt/stylesheet.rb +1 -1
- data/lib/nokogiri/xslt.rb +9 -5
- data/lib/nokogiri.rb +19 -25
- data/lib/xercesImpl.jar +0 -0
- data/nokogiri_help_responses.md +40 -0
- data/tasks/cross_compile.rb +130 -136
- data/tasks/nokogiri.org.rb +18 -0
- data/tasks/test.rb +2 -2
- data/test/css/test_parser.rb +29 -18
- data/test/css/test_tokenizer.rb +8 -0
- data/test/decorators/test_slop.rb +16 -0
- data/test/files/encoding.html +82 -0
- data/test/files/encoding.xhtml +84 -0
- data/test/files/metacharset.html +10 -0
- data/test/files/noencoding.html +47 -0
- data/test/helper.rb +5 -1
- data/test/html/sax/test_parser.rb +65 -3
- data/test/html/test_document.rb +75 -1
- data/test/html/test_document_encoding.rb +61 -0
- data/test/html/test_document_fragment.rb +50 -5
- data/test/html/test_element_description.rb +4 -2
- data/test/html/test_node.rb +9 -0
- data/test/test_memory_leak.rb +20 -35
- data/test/test_nokogiri.rb +14 -20
- data/test/test_reader.rb +23 -6
- data/test/test_xslt_transforms.rb +6 -2
- data/test/xml/node/test_save_options.rb +10 -2
- data/test/xml/sax/test_parser.rb +39 -8
- data/test/xml/sax/test_parser_context.rb +50 -0
- data/test/xml/sax/test_push_parser.rb +18 -1
- data/test/xml/test_attribute_decl.rb +7 -3
- data/test/xml/test_builder.rb +17 -0
- data/test/xml/test_document.rb +34 -5
- data/test/xml/test_document_fragment.rb +14 -2
- data/test/xml/test_dtd.rb +28 -3
- data/test/xml/test_element_content.rb +1 -1
- data/test/xml/test_element_decl.rb +1 -1
- data/test/xml/test_entity_decl.rb +12 -10
- data/test/xml/test_namespace.rb +7 -5
- data/test/xml/test_node.rb +65 -13
- data/test/xml/test_node_reparenting.rb +72 -31
- data/test/xml/test_node_set.rb +57 -0
- data/test/xml/test_schema.rb +5 -0
- data/test/xml/test_xpath.rb +32 -0
- data/test/xslt/test_custom_functions.rb +94 -0
- data/test/xslt/test_exception_handling.rb +37 -0
- metadata +512 -517
- data/deps.rip +0 -5
- data/ext/nokogiri/libcharset-1.dll +0 -0
- data/ext/nokogiri/libexslt.dll +0 -0
- data/ext/nokogiri/libiconv-2.dll +0 -0
- data/ext/nokogiri/libxml2.dll +0 -0
- data/ext/nokogiri/libxslt.dll +0 -0
- data/ext/nokogiri/zlib1.dll +0 -0
- data/lib/nokogiri/css/generated_parser.rb +0 -676
- data/lib/nokogiri/css/generated_tokenizer.rb +0 -146
- data/lib/nokogiri/ffi/encoding_handler.rb +0 -42
- data/lib/nokogiri/ffi/html/document.rb +0 -28
- data/lib/nokogiri/ffi/html/element_description.rb +0 -81
- data/lib/nokogiri/ffi/html/entity_lookup.rb +0 -16
- data/lib/nokogiri/ffi/html/sax/parser_context.rb +0 -38
- data/lib/nokogiri/ffi/io_callbacks.rb +0 -42
- data/lib/nokogiri/ffi/libxml.rb +0 -411
- data/lib/nokogiri/ffi/structs/common_node.rb +0 -38
- data/lib/nokogiri/ffi/structs/html_elem_desc.rb +0 -24
- data/lib/nokogiri/ffi/structs/html_entity_desc.rb +0 -13
- data/lib/nokogiri/ffi/structs/xml_alloc.rb +0 -16
- data/lib/nokogiri/ffi/structs/xml_attr.rb +0 -19
- data/lib/nokogiri/ffi/structs/xml_attribute.rb +0 -27
- data/lib/nokogiri/ffi/structs/xml_buffer.rb +0 -16
- data/lib/nokogiri/ffi/structs/xml_char_encoding_handler.rb +0 -11
- data/lib/nokogiri/ffi/structs/xml_document.rb +0 -117
- data/lib/nokogiri/ffi/structs/xml_dtd.rb +0 -28
- data/lib/nokogiri/ffi/structs/xml_element.rb +0 -26
- data/lib/nokogiri/ffi/structs/xml_element_content.rb +0 -17
- data/lib/nokogiri/ffi/structs/xml_entity.rb +0 -32
- data/lib/nokogiri/ffi/structs/xml_enumeration.rb +0 -12
- data/lib/nokogiri/ffi/structs/xml_node.rb +0 -28
- data/lib/nokogiri/ffi/structs/xml_node_set.rb +0 -53
- data/lib/nokogiri/ffi/structs/xml_notation.rb +0 -11
- data/lib/nokogiri/ffi/structs/xml_ns.rb +0 -15
- data/lib/nokogiri/ffi/structs/xml_parser_context.rb +0 -19
- data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +0 -14
- data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +0 -51
- data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +0 -124
- data/lib/nokogiri/ffi/structs/xml_schema.rb +0 -13
- data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +0 -31
- data/lib/nokogiri/ffi/structs/xml_text_reader.rb +0 -12
- data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +0 -38
- data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +0 -35
- data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +0 -20
- data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +0 -13
- data/lib/nokogiri/ffi/weak_bucket.rb +0 -40
- data/lib/nokogiri/ffi/xml/attr.rb +0 -41
- data/lib/nokogiri/ffi/xml/attribute_decl.rb +0 -27
- data/lib/nokogiri/ffi/xml/cdata.rb +0 -19
- data/lib/nokogiri/ffi/xml/comment.rb +0 -18
- data/lib/nokogiri/ffi/xml/document.rb +0 -166
- data/lib/nokogiri/ffi/xml/document_fragment.rb +0 -21
- data/lib/nokogiri/ffi/xml/dtd.rb +0 -67
- data/lib/nokogiri/ffi/xml/element_content.rb +0 -43
- data/lib/nokogiri/ffi/xml/element_decl.rb +0 -19
- data/lib/nokogiri/ffi/xml/entity_decl.rb +0 -36
- data/lib/nokogiri/ffi/xml/entity_reference.rb +0 -19
- data/lib/nokogiri/ffi/xml/namespace.rb +0 -44
- data/lib/nokogiri/ffi/xml/node.rb +0 -554
- data/lib/nokogiri/ffi/xml/node_set.rb +0 -149
- data/lib/nokogiri/ffi/xml/processing_instruction.rb +0 -20
- data/lib/nokogiri/ffi/xml/reader.rb +0 -236
- data/lib/nokogiri/ffi/xml/relax_ng.rb +0 -85
- data/lib/nokogiri/ffi/xml/sax/parser.rb +0 -135
- data/lib/nokogiri/ffi/xml/sax/parser_context.rb +0 -67
- data/lib/nokogiri/ffi/xml/sax/push_parser.rb +0 -51
- data/lib/nokogiri/ffi/xml/schema.rb +0 -109
- data/lib/nokogiri/ffi/xml/syntax_error.rb +0 -98
- data/lib/nokogiri/ffi/xml/text.rb +0 -18
- data/lib/nokogiri/ffi/xml/xpath.rb +0 -9
- data/lib/nokogiri/ffi/xml/xpath_context.rb +0 -148
- data/lib/nokogiri/ffi/xslt/stylesheet.rb +0 -53
- data/lib/nokogiri/version_warning.rb +0 -14
- data/test/ffi/test_document.rb +0 -35
|
@@ -74,6 +74,16 @@ module Nokogiri
|
|
|
74
74
|
assert Nokogiri::HTML::DocumentFragment.new(@html)
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
+
def test_body_fragment_should_contain_body
|
|
78
|
+
fragment = Nokogiri::HTML::DocumentFragment.parse(" <body><div>foo</div></body>")
|
|
79
|
+
assert_match(/^<body>/, fragment.to_s)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_nonbody_fragment_should_not_contain_body
|
|
83
|
+
fragment = Nokogiri::HTML::DocumentFragment.parse("<div>foo</div>")
|
|
84
|
+
assert_match(/^<div>/, fragment.to_s)
|
|
85
|
+
end
|
|
86
|
+
|
|
77
87
|
def test_fragment_should_have_document
|
|
78
88
|
fragment = Nokogiri::HTML::DocumentFragment.new(@html)
|
|
79
89
|
assert_equal @html, fragment.document
|
|
@@ -123,7 +133,8 @@ module Nokogiri
|
|
|
123
133
|
def test_html_fragment_has_outer_text
|
|
124
134
|
doc = "a<div>b</div>c"
|
|
125
135
|
fragment = Nokogiri::HTML::Document.new.fragment(doc)
|
|
126
|
-
if Nokogiri
|
|
136
|
+
if Nokogiri.uses_libxml? &&
|
|
137
|
+
Nokogiri::VERSION_INFO['libxml']['loaded'] <= "2.6.16"
|
|
127
138
|
assert_equal "a<div>b</div><p>c</p>", fragment.to_s
|
|
128
139
|
else
|
|
129
140
|
assert_equal "a<div>b</div>c", fragment.to_s
|
|
@@ -139,13 +150,13 @@ module Nokogiri
|
|
|
139
150
|
def test_html_fragment_with_leading_whitespace
|
|
140
151
|
doc = " <div>b</div> "
|
|
141
152
|
fragment = Nokogiri::HTML::Document.new.fragment(doc)
|
|
142
|
-
|
|
153
|
+
assert_match %r% <div>b</div> *%, fragment.to_s
|
|
143
154
|
end
|
|
144
155
|
|
|
145
156
|
def test_html_fragment_with_leading_whitespace_and_newline
|
|
146
157
|
doc = " \n<div>b</div> "
|
|
147
158
|
fragment = Nokogiri::HTML::Document.new.fragment(doc)
|
|
148
|
-
|
|
159
|
+
assert_match %r% \n<div>b</div> *%, fragment.to_s
|
|
149
160
|
end
|
|
150
161
|
|
|
151
162
|
def test_html_fragment_with_leading_text_and_newline
|
|
@@ -155,7 +166,7 @@ module Nokogiri
|
|
|
155
166
|
|
|
156
167
|
def test_html_fragment_with_leading_whitespace_and_text_and_newline
|
|
157
168
|
fragment = HTML::Document.new.fragment(" First line\nSecond line<br>Broken line")
|
|
158
|
-
assert_equal "First line\nSecond line<br>Broken line", fragment.to_s
|
|
169
|
+
assert_equal " First line\nSecond line<br>Broken line", fragment.to_s
|
|
159
170
|
end
|
|
160
171
|
|
|
161
172
|
def test_html_fragment_with_leading_entity
|
|
@@ -179,7 +190,8 @@ module Nokogiri
|
|
|
179
190
|
def test_to_xhtml
|
|
180
191
|
doc = "<span>foo<br></span><span>bar</span>"
|
|
181
192
|
fragment = Nokogiri::HTML::Document.new.fragment(doc)
|
|
182
|
-
if Nokogiri
|
|
193
|
+
if !Nokogiri.uses_libxml? ||
|
|
194
|
+
Nokogiri::VERSION_INFO['libxml']['loaded'] >= "2.7.0"
|
|
183
195
|
assert_equal "<span>foo<br /></span><span>bar</span>", fragment.to_xhtml
|
|
184
196
|
else
|
|
185
197
|
assert_equal "<span>foo<br></span><span>bar</span>", fragment.to_xhtml
|
|
@@ -205,6 +217,39 @@ module Nokogiri
|
|
|
205
217
|
assert_equal("<p>hello<!-- your ad here --></p>",
|
|
206
218
|
fragment.to_s)
|
|
207
219
|
end
|
|
220
|
+
|
|
221
|
+
def test_malformed_fragment_is_corrected
|
|
222
|
+
fragment = HTML::DocumentFragment.parse("<div </div>")
|
|
223
|
+
assert_equal "<div></div>", fragment.to_s
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def test_unclosed_script_tag
|
|
227
|
+
# see GH#315
|
|
228
|
+
fragment = HTML::DocumentFragment.parse("foo <script>bar")
|
|
229
|
+
assert_equal "foo <script>bar</script>", fragment.to_html
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def test_error_propagation_on_fragment_parse
|
|
233
|
+
frag = Nokogiri::HTML::DocumentFragment.parse "<hello>oh, hello there.</hello>"
|
|
234
|
+
assert frag.errors.any?{|err| err.to_s =~ /Tag hello invalid/}, "errors should be copied to the fragment"
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def test_error_propagation_on_fragment_parse_in_node_context
|
|
238
|
+
doc = Nokogiri::HTML::Document.parse "<html><body><div></div></body></html>"
|
|
239
|
+
context_node = doc.at_css "div"
|
|
240
|
+
frag = Nokogiri::HTML::DocumentFragment.new doc, "<hello>oh, hello there.</hello>", context_node
|
|
241
|
+
assert frag.errors.any?{|err| err.to_s =~ /Tag hello invalid/}, "errors should be on the context node's document"
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def test_error_propagation_on_fragment_parse_in_node_context_should_not_include_preexisting_errors
|
|
245
|
+
doc = Nokogiri::HTML::Document.parse "<html><body><div></div><jimmy></jimmy></body></html>"
|
|
246
|
+
assert doc.errors.any?{|err| err.to_s =~ /jimmy/}, "assert on setup"
|
|
247
|
+
|
|
248
|
+
context_node = doc.at_css "div"
|
|
249
|
+
frag = Nokogiri::HTML::DocumentFragment.new doc, "<hello>oh, hello there.</hello>", context_node
|
|
250
|
+
assert frag.errors.any?{|err| err.to_s =~ /Tag hello invalid/}, "errors should be on the context node's document"
|
|
251
|
+
assert frag.errors.none?{|err| err.to_s =~ /jimmy/}, "errors should not include pre-existing document errors"
|
|
252
|
+
end
|
|
208
253
|
end
|
|
209
254
|
end
|
|
210
255
|
end
|
|
@@ -56,10 +56,12 @@ module Nokogiri
|
|
|
56
56
|
|
|
57
57
|
def test_subelements
|
|
58
58
|
sub_elements = ElementDescription['body'].sub_elements
|
|
59
|
-
if Nokogiri::LIBXML_VERSION
|
|
59
|
+
if Nokogiri.uses_libxml? && Nokogiri::LIBXML_VERSION >= '2.7.7'
|
|
60
60
|
assert_equal 65, sub_elements.length
|
|
61
|
-
|
|
61
|
+
elsif Nokogiri.uses_libxml?
|
|
62
62
|
assert_equal 61, sub_elements.length
|
|
63
|
+
else
|
|
64
|
+
assert sub_elements.length > 0
|
|
63
65
|
end
|
|
64
66
|
end
|
|
65
67
|
|
data/test/html/test_node.rb
CHANGED
|
@@ -127,6 +127,15 @@ module Nokogiri
|
|
|
127
127
|
assert_equal 'foo&bar&baz', node['href']
|
|
128
128
|
end
|
|
129
129
|
|
|
130
|
+
def test_parse_config_option
|
|
131
|
+
node = @html.at('div')
|
|
132
|
+
options = nil
|
|
133
|
+
node.parse("<div></div>") do |config|
|
|
134
|
+
options = config
|
|
135
|
+
end
|
|
136
|
+
assert_equal Nokogiri::XML::ParseOptions::DEFAULT_HTML, options.to_i
|
|
137
|
+
end
|
|
138
|
+
|
|
130
139
|
def test_fragment_handler_does_not_regurge_on_invalid_attributes
|
|
131
140
|
iframe = %Q{<iframe style="width: 0%; height: 0px" src="http://someurl" allowtransparency></iframe>}
|
|
132
141
|
assert_nothing_raised { @html.at('div').fragment(iframe) }
|
data/test/test_memory_leak.rb
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
require "helper"
|
|
2
2
|
|
|
3
3
|
class TestMemoryLeak < Nokogiri::TestCase
|
|
4
|
-
|
|
5
4
|
if ENV['NOKOGIRI_GC'] # turning these off by default for now
|
|
6
|
-
|
|
7
5
|
def test_dont_hurt_em_why
|
|
8
6
|
content = File.open("#{File.dirname(__FILE__)}/files/dont_hurt_em_why.xml").read
|
|
9
7
|
ndoc = Nokogiri::XML(content)
|
|
@@ -14,6 +12,26 @@ class TestMemoryLeak < Nokogiri::TestCase
|
|
|
14
12
|
end
|
|
15
13
|
end
|
|
16
14
|
|
|
15
|
+
class BadIO
|
|
16
|
+
def read(*args)
|
|
17
|
+
raise 'hell'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def write(*args)
|
|
21
|
+
raise 'chickens'
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_for_mem_leak_on_io_callbacks
|
|
26
|
+
io = File.open SNUGGLES_FILE
|
|
27
|
+
Nokogiri::XML.parse(io)
|
|
28
|
+
|
|
29
|
+
(10**10).times do
|
|
30
|
+
Nokogiri::XML.parse(BadIO.new) rescue nil
|
|
31
|
+
doc.write BadIO.new rescue nil
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
17
35
|
def test_for_memory_leak
|
|
18
36
|
begin
|
|
19
37
|
# we don't use Dike in any tests, but requiring it has side effects
|
|
@@ -42,39 +60,6 @@ class TestMemoryLeak < Nokogiri::TestCase
|
|
|
42
60
|
puts "\ndike is not installed, skipping memory leak test"
|
|
43
61
|
end
|
|
44
62
|
end
|
|
45
|
-
|
|
46
|
-
if Nokogiri.ffi?
|
|
47
|
-
[ ['Node', 'p', nil],
|
|
48
|
-
['CDATA', nil, 'content'],
|
|
49
|
-
['Comment', nil, 'content'],
|
|
50
|
-
['DocumentFragment', nil],
|
|
51
|
-
['EntityReference', nil, 'p'],
|
|
52
|
-
['ProcessingInstruction', nil, 'p', 'content'] ].each do |klass, *args|
|
|
53
|
-
|
|
54
|
-
define_method "test_for_leaked_#{klass}_nodes" do
|
|
55
|
-
Nokogiri::LibXML.expects(:xmlAddChild).at_least(1) # more than once shows we're GCing properly
|
|
56
|
-
10.times {
|
|
57
|
-
xml = Nokogiri::XML("<root></root>")
|
|
58
|
-
2.times { Nokogiri::XML.const_get(klass).new(*(args.collect{|arg| arg || xml})) }
|
|
59
|
-
GC.start
|
|
60
|
-
}
|
|
61
|
-
GC.start
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def test_for_leaked_attr_nodes
|
|
67
|
-
Nokogiri::LibXML.expects(:xmlFreePropList).at_least(1) # more than once shows we're GCing properly
|
|
68
|
-
10.times {
|
|
69
|
-
xml = Nokogiri::XML("<root></root>")
|
|
70
|
-
2.times { Nokogiri::XML::Attr.new(xml, "p") }
|
|
71
|
-
GC.start
|
|
72
|
-
}
|
|
73
|
-
GC.start
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
end # if ffi
|
|
77
|
-
|
|
78
63
|
end # if NOKOGIRI_GC
|
|
79
64
|
|
|
80
65
|
private
|
data/test/test_nokogiri.rb
CHANGED
|
@@ -4,34 +4,28 @@ class TestNokogiri < Nokogiri::TestCase
|
|
|
4
4
|
def test_versions
|
|
5
5
|
version_match = /\d+\.\d+\.\d+/
|
|
6
6
|
assert_match version_match, Nokogiri::VERSION
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
else
|
|
14
|
-
assert_equal 'ruby', Nokogiri::VERSION_INFO['libxml']['platform']
|
|
15
|
-
end
|
|
16
|
-
assert Nokogiri.ffi?
|
|
17
|
-
else
|
|
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
|
|
18
13
|
assert_equal 'extension', Nokogiri::VERSION_INFO['libxml']['binding']
|
|
19
14
|
|
|
20
15
|
assert_match version_match, Nokogiri::VERSION_INFO['libxml']['compiled']
|
|
21
16
|
assert_equal Nokogiri::LIBXML_VERSION, Nokogiri::VERSION_INFO['libxml']['compiled']
|
|
22
|
-
assert ! Nokogiri.ffi?
|
|
23
|
-
end
|
|
24
17
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
31
25
|
end
|
|
32
26
|
|
|
33
27
|
def test_libxml_iconv
|
|
34
|
-
assert Nokogiri.const_defined?(:LIBXML_ICONV_ENABLED)
|
|
28
|
+
assert Nokogiri.const_defined?(:LIBXML_ICONV_ENABLED) if Nokogiri.uses_libxml?
|
|
35
29
|
end
|
|
36
30
|
|
|
37
31
|
def test_parse_with_io
|
data/test/test_reader.rb
CHANGED
|
@@ -81,6 +81,28 @@ class TestReader < Nokogiri::TestCase
|
|
|
81
81
|
assert_equal [false, false, false, false, false, false, false],
|
|
82
82
|
reader.map { |x| x.default? }
|
|
83
83
|
end
|
|
84
|
+
|
|
85
|
+
class ReallyBadIO
|
|
86
|
+
def read(size)
|
|
87
|
+
'a' * size ** 10
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
class ReallyBadIO4Java
|
|
92
|
+
def read(size=1)
|
|
93
|
+
'a' * size ** 10
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def test_io_that_reads_too_much
|
|
98
|
+
if Nokogiri.jruby?
|
|
99
|
+
io = ReallyBadIO4Java.new
|
|
100
|
+
Nokogiri::XML::Reader(io)
|
|
101
|
+
else
|
|
102
|
+
io = ReallyBadIO.new
|
|
103
|
+
Nokogiri::XML::Reader(io)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
84
106
|
|
|
85
107
|
def test_in_memory
|
|
86
108
|
assert Nokogiri::XML::Reader(<<-eoxml)
|
|
@@ -97,12 +119,7 @@ class TestReader < Nokogiri::TestCase
|
|
|
97
119
|
</x>
|
|
98
120
|
eoxml
|
|
99
121
|
reader = Nokogiri::XML::Reader(xml)
|
|
100
|
-
|
|
101
|
-
assert_not_nil reader.source
|
|
102
|
-
assert reader.source.is_a?(FFI::MemoryPointer)
|
|
103
|
-
else
|
|
104
|
-
assert_equal xml, reader.source
|
|
105
|
-
end
|
|
122
|
+
assert_equal xml, reader.source
|
|
106
123
|
end
|
|
107
124
|
|
|
108
125
|
def test_default?
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
require "helper"
|
|
2
2
|
|
|
3
3
|
class TestXsltTransforms < Nokogiri::TestCase
|
|
4
|
-
|
|
5
4
|
def setup
|
|
6
5
|
@doc = Nokogiri::XML(File.open(XML_FILE))
|
|
7
6
|
end
|
|
@@ -179,11 +178,16 @@ encoding="iso-8859-1" indent="yes"/>
|
|
|
179
178
|
assert_raises(RuntimeError) { Nokogiri::XSLT.parse(xslt_str) }
|
|
180
179
|
end
|
|
181
180
|
|
|
181
|
+
def test_passing_a_non_document_to_transform
|
|
182
|
+
xsl = Nokogiri::XSLT('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"></xsl:stylesheet>')
|
|
183
|
+
assert_raises(ArgumentError) { xsl.transform("<div></div>") }
|
|
184
|
+
assert_raises(ArgumentError) { xsl.transform(Nokogiri::HTML("").css("body")) }
|
|
185
|
+
end
|
|
186
|
+
|
|
182
187
|
def check_params result_doc, params
|
|
183
188
|
result_doc.xpath('/root/params/*').each do |p|
|
|
184
189
|
assert_equal p.content, params[p.name.intern]
|
|
185
190
|
end
|
|
186
191
|
end
|
|
187
|
-
|
|
188
192
|
end
|
|
189
193
|
end
|
|
@@ -5,14 +5,22 @@ module Nokogiri
|
|
|
5
5
|
class Node
|
|
6
6
|
class TestSaveOptions < Nokogiri::TestCase
|
|
7
7
|
SaveOptions.constants.each do |constant|
|
|
8
|
-
class_eval
|
|
8
|
+
class_eval <<-EOEVAL
|
|
9
9
|
def test_predicate_#{constant.downcase}
|
|
10
10
|
options = SaveOptions.new(SaveOptions::#{constant})
|
|
11
11
|
assert options.#{constant.downcase}?
|
|
12
12
|
|
|
13
13
|
assert SaveOptions.new.#{constant.downcase}.#{constant.downcase}?
|
|
14
14
|
end
|
|
15
|
-
|
|
15
|
+
EOEVAL
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_default_xml_save_options
|
|
19
|
+
if Nokogiri.jruby?
|
|
20
|
+
assert_equal 0, (SaveOptions::DEFAULT_XML & SaveOptions::FORMAT)
|
|
21
|
+
else
|
|
22
|
+
assert_equal SaveOptions::FORMAT, (SaveOptions::DEFAULT_XML & SaveOptions::FORMAT)
|
|
23
|
+
end
|
|
16
24
|
end
|
|
17
25
|
end
|
|
18
26
|
end
|
data/test/xml/sax/test_parser.rb
CHANGED
|
@@ -24,7 +24,7 @@ module Nokogiri
|
|
|
24
24
|
|
|
25
25
|
assert block_called
|
|
26
26
|
|
|
27
|
-
assert_equal ['a', '&b'], doc.start_elements
|
|
27
|
+
assert_equal [['foo', [['a', '&b']]]], doc.start_elements
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def test_parser_context_yielded_in_memory
|
|
@@ -40,7 +40,7 @@ module Nokogiri
|
|
|
40
40
|
|
|
41
41
|
assert block_called
|
|
42
42
|
|
|
43
|
-
assert_equal ['a', '&b'], doc.start_elements
|
|
43
|
+
assert_equal [['foo', [['a', '&b']]]], doc.start_elements
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def test_xml_decl
|
|
@@ -95,6 +95,7 @@ module Nokogiri
|
|
|
95
95
|
<foo:bar>hello world</foo:bar>
|
|
96
96
|
</root>
|
|
97
97
|
eoxml
|
|
98
|
+
|
|
98
99
|
assert @parser.document.start_elements_namespace.length > 0
|
|
99
100
|
el = @parser.document.start_elements_namespace[1]
|
|
100
101
|
assert_equal 'a', el.first
|
|
@@ -144,8 +145,12 @@ module Nokogiri
|
|
|
144
145
|
end
|
|
145
146
|
|
|
146
147
|
def test_start_is_called_without_namespace
|
|
147
|
-
@parser.parse(
|
|
148
|
-
|
|
148
|
+
@parser.parse(<<-eoxml)
|
|
149
|
+
<root xmlns:foo='http://foo.example.com/' xmlns='http://example.com/'>
|
|
150
|
+
<foo:f><bar></foo:f>
|
|
151
|
+
</root>
|
|
152
|
+
eoxml
|
|
153
|
+
assert_equal ['root', 'foo:f', 'bar'],
|
|
149
154
|
@parser.document.start_elements.map { |x| x.first }
|
|
150
155
|
end
|
|
151
156
|
|
|
@@ -291,15 +296,41 @@ module Nokogiri
|
|
|
291
296
|
@parser.parse_memory(<<-eoxml)
|
|
292
297
|
<p id="asdfasdf">Paragraph 1</p>
|
|
293
298
|
eoxml
|
|
294
|
-
assert_equal [["p", ["id", "asdfasdf"]]],
|
|
299
|
+
assert_equal [["p", [["id", "asdfasdf"]]]],
|
|
295
300
|
@parser.document.start_elements
|
|
296
301
|
end
|
|
297
302
|
|
|
298
|
-
def
|
|
303
|
+
def test_start_element_attrs_include_namespaces
|
|
299
304
|
@parser.parse_memory(<<-eoxml)
|
|
300
|
-
<p>Paragraph 1</p>
|
|
301
|
-
<p>Paragraph 2</p>
|
|
305
|
+
<p xmlns:foo='http://foo.example.com/'>Paragraph 1</p>
|
|
302
306
|
eoxml
|
|
307
|
+
assert_equal [["p", [['xmlns:foo', 'http://foo.example.com/']]]],
|
|
308
|
+
@parser.document.start_elements
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
if Nokogiri.uses_libxml? # JRuby SAXParser only parses well-formed XML documents
|
|
312
|
+
def test_parse_document
|
|
313
|
+
@parser.parse_memory(<<-eoxml)
|
|
314
|
+
<p>Paragraph 1</p>
|
|
315
|
+
<p>Paragraph 2</p>
|
|
316
|
+
eoxml
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
def test_parser_attributes
|
|
321
|
+
xml = <<-eoxml
|
|
322
|
+
<?xml version="1.0" ?><root><foo a="&b" c=">d" /></root>
|
|
323
|
+
eoxml
|
|
324
|
+
|
|
325
|
+
block_called = false
|
|
326
|
+
@parser.parse(xml) { |ctx|
|
|
327
|
+
block_called = true
|
|
328
|
+
ctx.replace_entities = true
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
assert block_called
|
|
332
|
+
|
|
333
|
+
assert_equal [['root', []], ['foo', [['a', '&b'], ['c', '>d']]]], @parser.document.start_elements
|
|
303
334
|
end
|
|
304
335
|
end
|
|
305
336
|
end
|
|
@@ -6,6 +6,56 @@ module Nokogiri
|
|
|
6
6
|
module XML
|
|
7
7
|
module SAX
|
|
8
8
|
class TestParserContext < Nokogiri::SAX::TestCase
|
|
9
|
+
def setup
|
|
10
|
+
@xml = '<hello>
|
|
11
|
+
|
|
12
|
+
world
|
|
13
|
+
<inter>
|
|
14
|
+
<net>
|
|
15
|
+
</net>
|
|
16
|
+
</inter>
|
|
17
|
+
|
|
18
|
+
</hello>'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class Counter < Nokogiri::XML::SAX::Document
|
|
22
|
+
attr_accessor :context, :lines, :columns
|
|
23
|
+
def initialize
|
|
24
|
+
@context = nil
|
|
25
|
+
@lines = []
|
|
26
|
+
@columns = []
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def start_element name, attrs = []
|
|
30
|
+
@lines << [name, context.line]
|
|
31
|
+
@columns << [name, context.column]
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_line_numbers
|
|
36
|
+
sax_handler = Counter.new
|
|
37
|
+
|
|
38
|
+
parser = Nokogiri::XML::SAX::Parser.new(sax_handler)
|
|
39
|
+
parser.parse(@xml) do |ctx|
|
|
40
|
+
sax_handler.context = ctx
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
assert_equal [["hello", 1], ["inter", 4], ["net", 5]],
|
|
44
|
+
sax_handler.lines
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_column_numbers
|
|
48
|
+
sax_handler = Counter.new
|
|
49
|
+
|
|
50
|
+
parser = Nokogiri::XML::SAX::Parser.new(sax_handler)
|
|
51
|
+
parser.parse(@xml) do |ctx|
|
|
52
|
+
sax_handler.context = ctx
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
assert_equal [["hello", 7], ["inter", 7], ["net", 9]],
|
|
56
|
+
sax_handler.columns
|
|
57
|
+
end
|
|
58
|
+
|
|
9
59
|
def test_replace_entities
|
|
10
60
|
pc = ParserContext.new StringIO.new('<root />'), 'UTF-8'
|
|
11
61
|
pc.replace_entities = false
|
|
@@ -38,7 +38,24 @@ module Nokogiri
|
|
|
38
38
|
<p id="asdfasdf">
|
|
39
39
|
eoxml
|
|
40
40
|
|
|
41
|
-
assert_equal [["p", ["id", "asdfasdf"]]],
|
|
41
|
+
assert_equal [["p", [["id", "asdfasdf"]]]],
|
|
42
|
+
@parser.document.start_elements
|
|
43
|
+
|
|
44
|
+
@parser.<<(<<-eoxml)
|
|
45
|
+
<!-- This is a comment -->
|
|
46
|
+
Paragraph 1
|
|
47
|
+
</p>
|
|
48
|
+
eoxml
|
|
49
|
+
assert_equal [' This is a comment '], @parser.document.comments
|
|
50
|
+
@parser.finish
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_start_element_with_namespaces
|
|
54
|
+
@parser.<<(<<-eoxml)
|
|
55
|
+
<p xmlns:foo="http://foo.example.com/">
|
|
56
|
+
eoxml
|
|
57
|
+
|
|
58
|
+
assert_equal [["p", [["xmlns:foo", "http://foo.example.com/"]]]],
|
|
42
59
|
@parser.document.start_elements
|
|
43
60
|
|
|
44
61
|
@parser.<<(<<-eoxml)
|
|
@@ -9,7 +9,7 @@ module Nokogiri
|
|
|
9
9
|
<?xml version="1.0"?><?TEST-STYLE PIDATA?>
|
|
10
10
|
<!DOCTYPE staff SYSTEM "staff.dtd" [
|
|
11
11
|
<!ATTLIST br width CDATA "0">
|
|
12
|
-
<!ATTLIST a width CDATA >
|
|
12
|
+
<!ATTLIST a width CDATA "0">
|
|
13
13
|
<!ATTLIST payment type (check|cash) "cash">
|
|
14
14
|
]>
|
|
15
15
|
<root />
|
|
@@ -64,12 +64,16 @@ module Nokogiri
|
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
def test_attribute_type
|
|
67
|
-
|
|
67
|
+
if Nokogiri.uses_libxml?
|
|
68
|
+
assert_equal 1, @attr_decl.attribute_type
|
|
69
|
+
else
|
|
70
|
+
assert_equal 'CDATA', @attr_decl.attribute_type
|
|
71
|
+
end
|
|
68
72
|
end
|
|
69
73
|
|
|
70
74
|
def test_default
|
|
71
75
|
assert_equal '0', @attr_decl.default
|
|
72
|
-
|
|
76
|
+
assert_equal '0', @attrs[1].default
|
|
73
77
|
end
|
|
74
78
|
|
|
75
79
|
def test_enumeration
|
data/test/xml/test_builder.rb
CHANGED
|
@@ -3,6 +3,23 @@ require "helper"
|
|
|
3
3
|
module Nokogiri
|
|
4
4
|
module XML
|
|
5
5
|
class TestBuilder < Nokogiri::TestCase
|
|
6
|
+
def test_attribute_sensitivity
|
|
7
|
+
xml = Nokogiri::XML::Builder.new { |x|
|
|
8
|
+
x.tag "hello", "abcDef" => "world"
|
|
9
|
+
}.to_xml
|
|
10
|
+
doc = Nokogiri.XML xml
|
|
11
|
+
assert_equal 'world', doc.root['abcDef']
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_builder_escape
|
|
15
|
+
xml = Nokogiri::XML::Builder.new { |x|
|
|
16
|
+
x.condition "value < 1", :attr => "value < 1"
|
|
17
|
+
}.to_xml
|
|
18
|
+
doc = Nokogiri.XML xml
|
|
19
|
+
assert_equal 'value < 1', doc.root['attr']
|
|
20
|
+
assert_equal 'value < 1', doc.root.content
|
|
21
|
+
end
|
|
22
|
+
|
|
6
23
|
def test_builder_namespace
|
|
7
24
|
doc = Nokogiri::XML::Builder.new { |xml|
|
|
8
25
|
xml.a("xmlns:a" => "x") do
|
data/test/xml/test_document.rb
CHANGED
|
@@ -217,7 +217,12 @@ module Nokogiri
|
|
|
217
217
|
end
|
|
218
218
|
|
|
219
219
|
def test_validate
|
|
220
|
-
|
|
220
|
+
if Nokogiri.uses_libxml?
|
|
221
|
+
assert_equal 44, @xml.validate.length
|
|
222
|
+
else
|
|
223
|
+
xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) {|cfg| cfg.dtdvalid}
|
|
224
|
+
assert_equal 37, xml.validate.length
|
|
225
|
+
end
|
|
221
226
|
end
|
|
222
227
|
|
|
223
228
|
def test_validate_no_internal_subset
|
|
@@ -329,12 +334,12 @@ module Nokogiri
|
|
|
329
334
|
end
|
|
330
335
|
|
|
331
336
|
def test_non_existant_function
|
|
332
|
-
# WTF. I don't know why this is different between MRI and
|
|
337
|
+
# WTF. I don't know why this is different between MRI and Jruby
|
|
333
338
|
# They should be the same... Either way, raising an exception
|
|
334
339
|
# is the correct thing to do.
|
|
335
340
|
exception = RuntimeError
|
|
336
341
|
|
|
337
|
-
if Nokogiri::VERSION_INFO['libxml']['platform'] == 'jruby'
|
|
342
|
+
if !Nokogiri.uses_libxml? || (Nokogiri.uses_libxml? && Nokogiri::VERSION_INFO['libxml']['platform'] == 'jruby')
|
|
338
343
|
exception = Nokogiri::XML::XPath::SyntaxError
|
|
339
344
|
end
|
|
340
345
|
|
|
@@ -406,7 +411,7 @@ module Nokogiri
|
|
|
406
411
|
end
|
|
407
412
|
|
|
408
413
|
# wtf... osx's libxml sucks.
|
|
409
|
-
unless Nokogiri::LIBXML_VERSION =~ /^2\.6\./
|
|
414
|
+
unless !Nokogiri.uses_libxml? || Nokogiri::LIBXML_VERSION =~ /^2\.6\./
|
|
410
415
|
def test_encoding
|
|
411
416
|
xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE, 'UTF-8')
|
|
412
417
|
assert_equal 'UTF-8', xml.encoding
|
|
@@ -606,7 +611,7 @@ module Nokogiri
|
|
|
606
611
|
<a:foo>hello from a</a:foo>
|
|
607
612
|
<b:foo>hello from b</b:foo>
|
|
608
613
|
<container xmlns:c="http://c.flavorjon.es/">
|
|
609
|
-
<c:foo>hello from c</c:foo>
|
|
614
|
+
<c:foo c:attr='attr-value'>hello from c</c:foo>
|
|
610
615
|
</container>
|
|
611
616
|
</root>
|
|
612
617
|
EOX
|
|
@@ -620,6 +625,7 @@ module Nokogiri
|
|
|
620
625
|
assert_equal 1, doc.xpath("//a:foo").length
|
|
621
626
|
assert_equal 1, doc.xpath("//a:foo").length
|
|
622
627
|
assert_equal 1, doc.xpath("//x:foo", "x" => "http://c.flavorjon.es/").length
|
|
628
|
+
assert_match %r{foo c:attr}, doc.to_xml
|
|
623
629
|
|
|
624
630
|
doc.remove_namespaces!
|
|
625
631
|
|
|
@@ -629,6 +635,7 @@ module Nokogiri
|
|
|
629
635
|
assert_equal 0, doc.xpath("//a:foo", namespaces).length
|
|
630
636
|
assert_equal 0, doc.xpath("//a:foo", namespaces).length
|
|
631
637
|
assert_equal 0, doc.xpath("//x:foo", "x" => "http://c.flavorjon.es/").length
|
|
638
|
+
assert_match %r{foo attr}, doc.to_xml
|
|
632
639
|
end
|
|
633
640
|
|
|
634
641
|
def test_subset_is_decorated
|
|
@@ -663,6 +670,28 @@ module Nokogiri
|
|
|
663
670
|
assert @xml.root.respond_to?(:awesome!)
|
|
664
671
|
assert @xml.children.respond_to?(:awesome!)
|
|
665
672
|
end
|
|
673
|
+
|
|
674
|
+
def test_java_integration
|
|
675
|
+
if Nokogiri.jruby?
|
|
676
|
+
require 'java'
|
|
677
|
+
factory = javax.xml.parsers.DocumentBuilderFactory.newInstance
|
|
678
|
+
builder = factory.newDocumentBuilder
|
|
679
|
+
document = builder.newDocument
|
|
680
|
+
root = document.createElement("foo")
|
|
681
|
+
document.appendChild(root)
|
|
682
|
+
noko_doc = Nokogiri::XML::Document.wrap(document)
|
|
683
|
+
assert_equal 'foo', noko_doc.root.name
|
|
684
|
+
|
|
685
|
+
noko_doc = Nokogiri::XML(<<eoxml)
|
|
686
|
+
<foo xmlns='hello'>
|
|
687
|
+
<bar xmlns:foo='world' />
|
|
688
|
+
</foo>
|
|
689
|
+
eoxml
|
|
690
|
+
dom = noko_doc.to_java
|
|
691
|
+
assert dom.kind_of? org.w3c.dom.Document
|
|
692
|
+
assert_equal 'foo', dom.getDocumentElement().getTagName()
|
|
693
|
+
end
|
|
694
|
+
end
|
|
666
695
|
end
|
|
667
696
|
end
|
|
668
697
|
end
|