nokogiri 1.7.2-java → 1.8.0-java
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/.cross_rubies +4 -4
- data/.travis.yml +43 -24
- data/CHANGELOG.md +54 -6
- data/Gemfile +8 -7
- data/Gemfile-libxml-ruby +3 -0
- data/LICENSE-DEPENDENCIES.md +1612 -0
- data/{LICENSE.txt → LICENSE.md} +1 -1
- data/Manifest.txt +5 -8
- data/README.md +8 -5
- data/Rakefile +15 -31
- data/appveyor.yml +2 -0
- data/dependencies.yml +12 -7
- data/ext/java/nokogiri/HtmlDocument.java +2 -2
- data/ext/java/nokogiri/HtmlSaxParserContext.java +20 -21
- data/ext/java/nokogiri/HtmlSaxPushParser.java +6 -10
- data/ext/java/nokogiri/NokogiriService.java +10 -31
- data/ext/java/nokogiri/XmlAttr.java +1 -26
- data/ext/java/nokogiri/XmlCdata.java +0 -1
- data/ext/java/nokogiri/XmlComment.java +1 -1
- data/ext/java/nokogiri/XmlDocument.java +4 -5
- data/ext/java/nokogiri/XmlDocumentFragment.java +29 -21
- data/ext/java/nokogiri/XmlDtd.java +1 -1
- data/ext/java/nokogiri/XmlElement.java +9 -10
- data/ext/java/nokogiri/XmlEntityDecl.java +4 -5
- data/ext/java/nokogiri/XmlNode.java +105 -103
- data/ext/java/nokogiri/XmlNodeSet.java +64 -76
- data/ext/java/nokogiri/XmlReader.java +48 -48
- data/ext/java/nokogiri/XmlRelaxng.java +1 -1
- data/ext/java/nokogiri/XmlSaxPushParser.java +37 -17
- data/ext/java/nokogiri/XmlSchema.java +7 -5
- data/ext/java/nokogiri/XmlSyntaxError.java +47 -35
- data/ext/java/nokogiri/XmlXpathContext.java +160 -132
- data/ext/java/nokogiri/XsltStylesheet.java +15 -24
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +19 -23
- data/ext/java/nokogiri/internals/NokogiriDomParser.java +1 -1
- data/ext/java/nokogiri/internals/NokogiriEncodingReaderWrapper.java +1 -1
- data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +11 -13
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +5 -21
- data/ext/java/nokogiri/internals/NokogiriHandler.java +1 -1
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +105 -142
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +16 -26
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +32 -50
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +10 -13
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +3 -10
- data/ext/java/nokogiri/internals/ParserContext.java +4 -8
- data/ext/java/nokogiri/internals/ReaderNode.java +53 -93
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +77 -89
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +6 -9
- data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +167 -0
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +17 -6
- data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +1 -1
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +28 -28
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +3 -4
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +2 -2
- data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +10 -10
- data/ext/java/nokogiri/internals/c14n/ElementProxy.java +5 -5
- data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +2 -2
- data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +1 -1
- data/ext/java/nokogiri/internals/c14n/XMLUtils.java +2 -2
- data/ext/java/org/apache/xml/dtm/ref/dom2dtm/DOM2DTMExt.java +1749 -0
- data/ext/nokogiri/extconf.rb +12 -17
- data/ext/nokogiri/nokogiri.h +0 -10
- data/ext/nokogiri/xml_attr.c +12 -8
- data/ext/nokogiri/xml_node.c +17 -14
- data/ext/nokogiri/xml_sax_push_parser.c +56 -12
- data/lib/nokogiri/html/sax/parser.rb +10 -0
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version.rb +5 -4
- data/lib/nokogiri/xml/document.rb +9 -9
- data/lib/nokogiri/xml/node.rb +7 -7
- data/lib/nokogiri/xml/node_set.rb +12 -7
- data/lib/nokogiri/xml/sax/parser.rb +6 -7
- data/lib/nokogiri/xml/searchable.rb +34 -25
- data/lib/nokogiri/xml/syntax_error.rb +24 -1
- data/test/decorators/test_slop.rb +4 -1
- data/test/helper.rb +10 -0
- data/test/html/sax/test_parser.rb +27 -0
- data/test/html/test_document.rb +12 -1
- data/test/html/test_document_encoding.rb +1 -3
- data/test/html/test_document_fragment.rb +3 -0
- data/test/xml/sax/test_push_parser.rb +48 -0
- data/test/xml/test_attr.rb +7 -0
- data/test/xml/test_document.rb +1 -1
- data/test/xml/test_document_fragment.rb +27 -0
- data/test/xml/test_entity_reference.rb +2 -2
- data/test/xml/test_node.rb +12 -15
- data/test/xml/test_node_reparenting.rb +14 -0
- data/test/xml/test_node_set.rb +8 -6
- data/test/xml/test_reader.rb +19 -0
- data/test/xml/test_syntax_error.rb +21 -15
- data/test/xml/test_unparented_node.rb +54 -11
- data/test/xml/test_xpath.rb +23 -6
- metadata +32 -20
- data/ext/java/nokogiri/internals/NokogiriDocumentCache.java +0 -73
- data/ext/java/nokogiri/internals/XsltExtensionFunction.java +0 -72
- data/suppressions/nokogiri_ree-1.8.7.358.supp +0 -61
- data/suppressions/nokogiri_ruby-1.8.7.370.supp +0 -0
- data/suppressions/nokogiri_ruby-1.9.2.320.supp +0 -28
- data/suppressions/nokogiri_ruby-1.9.3.327.supp +0 -28
- data/test_all +0 -105
@@ -11,6 +11,8 @@ module Nokogiri
|
|
11
11
|
# The Document this NodeSet is associated with
|
12
12
|
attr_accessor :document
|
13
13
|
|
14
|
+
alias :clone :dup
|
15
|
+
|
14
16
|
# Create a NodeSet with +document+ defaulting to +list+
|
15
17
|
def initialize document, list = []
|
16
18
|
@document = document
|
@@ -71,9 +73,10 @@ module Nokogiri
|
|
71
73
|
# For more information see Nokogiri::XML::Searchable#css
|
72
74
|
def css *args
|
73
75
|
rules, handler, ns, _ = extract_params(args)
|
76
|
+
paths = css_rules_to_xpath(rules, ns)
|
74
77
|
|
75
78
|
inject(NodeSet.new(document)) do |set, node|
|
76
|
-
set
|
79
|
+
set + xpath_internal(node, paths, handler, ns, nil)
|
77
80
|
end
|
78
81
|
end
|
79
82
|
|
@@ -88,7 +91,7 @@ module Nokogiri
|
|
88
91
|
paths, handler, ns, binds = extract_params(args)
|
89
92
|
|
90
93
|
inject(NodeSet.new(document)) do |set, node|
|
91
|
-
set
|
94
|
+
set + xpath_internal(node, paths, handler, ns, binds)
|
92
95
|
end
|
93
96
|
end
|
94
97
|
|
@@ -290,7 +293,11 @@ module Nokogiri
|
|
290
293
|
# Returns a new NodeSet containing all the children of all the nodes in
|
291
294
|
# the NodeSet
|
292
295
|
def children
|
293
|
-
|
296
|
+
node_set = NodeSet.new(document)
|
297
|
+
each do |node|
|
298
|
+
node.children.each { |n| node_set.push(n) }
|
299
|
+
end
|
300
|
+
node_set
|
294
301
|
end
|
295
302
|
|
296
303
|
###
|
@@ -312,11 +319,9 @@ module Nokogiri
|
|
312
319
|
|
313
320
|
alias :+ :|
|
314
321
|
|
315
|
-
private
|
322
|
+
# @private
|
323
|
+
IMPLIED_XPATH_CONTEXTS = [ './/'.freeze, 'self::'.freeze ].freeze # :nodoc:
|
316
324
|
|
317
|
-
def implied_xpath_contexts # :nodoc:
|
318
|
-
[".//", "self::"]
|
319
|
-
end
|
320
325
|
end
|
321
326
|
end
|
322
327
|
end
|
@@ -68,8 +68,7 @@ module Nokogiri
|
|
68
68
|
|
69
69
|
# Create a new Parser with +doc+ and +encoding+
|
70
70
|
def initialize doc = Nokogiri::XML::SAX::Document.new, encoding = 'UTF-8'
|
71
|
-
check_encoding(encoding)
|
72
|
-
@encoding = encoding
|
71
|
+
@encoding = check_encoding(encoding)
|
73
72
|
@document = doc
|
74
73
|
@warned = false
|
75
74
|
end
|
@@ -88,9 +87,8 @@ module Nokogiri
|
|
88
87
|
###
|
89
88
|
# Parse given +io+
|
90
89
|
def parse_io io, encoding = 'ASCII'
|
91
|
-
check_encoding(encoding)
|
92
|
-
|
93
|
-
ctx = ParserContext.io(io, ENCODINGS[encoding])
|
90
|
+
@encoding = check_encoding(encoding)
|
91
|
+
ctx = ParserContext.io(io, ENCODINGS[@encoding])
|
94
92
|
yield ctx if block_given?
|
95
93
|
ctx.parse_with self
|
96
94
|
end
|
@@ -114,8 +112,9 @@ module Nokogiri
|
|
114
112
|
|
115
113
|
private
|
116
114
|
def check_encoding(encoding)
|
117
|
-
encoding.upcase
|
118
|
-
|
115
|
+
encoding.upcase.tap do |enc|
|
116
|
+
raise ArgumentError.new("'#{enc}' is not a valid encoding") unless ENCODINGS[enc]
|
117
|
+
end
|
119
118
|
end
|
120
119
|
end
|
121
120
|
end
|
@@ -149,30 +149,9 @@ module Nokogiri
|
|
149
149
|
# }.new)
|
150
150
|
#
|
151
151
|
def xpath *args
|
152
|
-
return NodeSet.new(document) unless document
|
153
|
-
|
154
152
|
paths, handler, ns, binds = extract_params(args)
|
155
153
|
|
156
|
-
|
157
|
-
ctx = XPathContext.new(self)
|
158
|
-
ctx.register_namespaces(ns)
|
159
|
-
path = path.gsub(/xmlns:/, ' :') unless Nokogiri.uses_libxml?
|
160
|
-
|
161
|
-
binds.each do |key,value|
|
162
|
-
ctx.register_variable key.to_s, value
|
163
|
-
end if binds
|
164
|
-
|
165
|
-
ctx.evaluate(path, handler)
|
166
|
-
end
|
167
|
-
return sets.first if sets.length == 1
|
168
|
-
|
169
|
-
NodeSet.new(document) do |combined|
|
170
|
-
sets.each do |set|
|
171
|
-
set.each do |node|
|
172
|
-
combined << node
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
154
|
+
xpath_internal self, paths, handler, ns, binds
|
176
155
|
end
|
177
156
|
|
178
157
|
##
|
@@ -189,12 +168,42 @@ module Nokogiri
|
|
189
168
|
private
|
190
169
|
|
191
170
|
def css_internal node, rules, handler, ns
|
192
|
-
|
193
|
-
|
171
|
+
xpath_internal node, css_rules_to_xpath(rules, ns), handler, ns, nil
|
172
|
+
end
|
173
|
+
|
174
|
+
def xpath_internal node, paths, handler, ns, binds
|
175
|
+
document = node.document
|
176
|
+
return NodeSet.new(document) unless document
|
177
|
+
|
178
|
+
if paths.length == 1
|
179
|
+
return xpath_impl(node, paths.first, handler, ns, binds)
|
180
|
+
end
|
181
|
+
|
182
|
+
NodeSet.new(document) do |combined|
|
183
|
+
paths.each do |path|
|
184
|
+
xpath_impl(node, path, handler, ns, binds).each { |set| combined << set }
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def xpath_impl node, path, handler, ns, binds
|
190
|
+
ctx = XPathContext.new(node)
|
191
|
+
ctx.register_namespaces(ns)
|
192
|
+
path = path.gsub(/xmlns:/, ' :') unless Nokogiri.uses_libxml?
|
193
|
+
|
194
|
+
binds.each do |key,value|
|
195
|
+
ctx.register_variable key.to_s, value
|
196
|
+
end if binds
|
197
|
+
|
198
|
+
ctx.evaluate(path, handler)
|
199
|
+
end
|
200
|
+
|
201
|
+
def css_rules_to_xpath(rules, ns)
|
202
|
+
rules.map { |rule| xpath_query_from_css_rule(rule, ns) }
|
194
203
|
end
|
195
204
|
|
196
205
|
def xpath_query_from_css_rule rule, ns
|
197
|
-
|
206
|
+
self.class::IMPLIED_XPATH_CONTEXTS.map do |implied_xpath_context|
|
198
207
|
CSS.xpath_for(rule.to_s, :prefix => implied_xpath_context, :ns => ns)
|
199
208
|
end.join(' | ')
|
200
209
|
end
|
@@ -40,7 +40,30 @@ module Nokogiri
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def to_s
|
43
|
-
super.chomp
|
43
|
+
message = super.chomp
|
44
|
+
[location_to_s, level_to_s, message].
|
45
|
+
compact.join(": ").
|
46
|
+
force_encoding(message.encoding)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def level_to_s
|
52
|
+
case level
|
53
|
+
when 3 then "FATAL"
|
54
|
+
when 2 then "ERROR"
|
55
|
+
when 1 then "WARNING"
|
56
|
+
else nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def nil_or_zero?(attribute)
|
61
|
+
attribute.nil? || attribute.zero?
|
62
|
+
end
|
63
|
+
|
64
|
+
def location_to_s
|
65
|
+
return nil if nil_or_zero?(line) && nil_or_zero?(column)
|
66
|
+
"#{line}:#{column}"
|
44
67
|
end
|
45
68
|
end
|
46
69
|
end
|
@@ -9,10 +9,13 @@ module Nokogiri
|
|
9
9
|
<description>this is the foo thing</description>
|
10
10
|
</item>
|
11
11
|
eoxml
|
12
|
+
|
12
13
|
assert doc.item.respond_to?(:title)
|
13
14
|
assert_equal 'foo', doc.item.title.text
|
15
|
+
|
14
16
|
assert doc.item.respond_to?(:_description), 'should have description'
|
15
|
-
|
17
|
+
assert_equal 'this is the foo thing', doc.item._description.text
|
18
|
+
|
16
19
|
assert !doc.item.respond_to?(:foo)
|
17
20
|
assert_raise(NoMethodError) { doc.item.foo }
|
18
21
|
end
|
data/test/helper.rb
CHANGED
@@ -7,7 +7,17 @@ require 'tempfile'
|
|
7
7
|
require 'pp'
|
8
8
|
|
9
9
|
require 'nokogiri'
|
10
|
+
|
10
11
|
if ENV['TEST_NOKOGIRI_WITH_LIBXML_RUBY']
|
12
|
+
#
|
13
|
+
# if you'd like to test with the libxml-ruby gem loaded, it's
|
14
|
+
# recommended that you set
|
15
|
+
#
|
16
|
+
# BUNDLE_GEMFILE=Gemfile-libxml-ruby
|
17
|
+
#
|
18
|
+
# which will a) bundle that gem, and b) set the appropriate env var to
|
19
|
+
# trigger this block
|
20
|
+
#
|
11
21
|
require 'libxml'
|
12
22
|
warn "#{__FILE__}:#{__LINE__}: loaded libxml-ruby '#{LibXML::XML::VERSION}'"
|
13
23
|
end
|
@@ -132,6 +132,33 @@ module Nokogiri
|
|
132
132
|
], @parser.document.start_elements
|
133
133
|
end
|
134
134
|
|
135
|
+
HTML_WITH_BR_TAG = <<-EOF
|
136
|
+
<html>
|
137
|
+
<head></head>
|
138
|
+
<body>
|
139
|
+
<div>
|
140
|
+
hello
|
141
|
+
<br>
|
142
|
+
</div>
|
143
|
+
|
144
|
+
<div>
|
145
|
+
hello again
|
146
|
+
</div>
|
147
|
+
</body>
|
148
|
+
</html>
|
149
|
+
EOF
|
150
|
+
|
151
|
+
def test_parsing_dom_error_from_string
|
152
|
+
@parser.parse(HTML_WITH_BR_TAG)
|
153
|
+
assert_equal 6, @parser.document.start_elements.length
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_parsing_dom_error_from_io
|
157
|
+
@parser.parse(StringIO.new(HTML_WITH_BR_TAG))
|
158
|
+
assert_equal 6, @parser.document.start_elements.length
|
159
|
+
end
|
160
|
+
|
161
|
+
|
135
162
|
def test_empty_processing_instruction
|
136
163
|
@parser.parse_memory("<strong>this will segfault<?strong>")
|
137
164
|
end
|
data/test/html/test_document.rb
CHANGED
@@ -15,7 +15,7 @@ module Nokogiri
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_does_not_fail_with_illformatted_html
|
18
|
-
doc = Nokogiri::HTML('"</html>";'.force_encoding(Encoding::BINARY))
|
18
|
+
doc = Nokogiri::HTML('"</html>";'.dup.force_encoding(Encoding::BINARY))
|
19
19
|
assert_not_nil doc
|
20
20
|
end
|
21
21
|
|
@@ -696,6 +696,17 @@ eohtml
|
|
696
696
|
node = html.xpath("//style").first
|
697
697
|
assert_equal("tr > div { display:block; }", node.inner_html)
|
698
698
|
end
|
699
|
+
|
700
|
+
it "does not fail when converting to_html using explicit encoding" do
|
701
|
+
html_fragment=<<-eos
|
702
|
+
<img width="16" height="16" src="images/icon.gif" border="0" alt="Inactive hide details for "User" ---19/05/2015 12:55:29---Provvediamo subito nell’integrare">
|
703
|
+
eos
|
704
|
+
doc = Nokogiri::HTML(html_fragment, nil, 'ISO-8859-1')
|
705
|
+
html = doc.to_html
|
706
|
+
assert html.index("src=\"images/icon.gif\"")
|
707
|
+
assert_equal 'ISO-8859-1', html.encoding.name
|
708
|
+
end
|
709
|
+
|
699
710
|
end
|
700
711
|
end
|
701
712
|
end
|
@@ -128,9 +128,7 @@ module Nokogiri
|
|
128
128
|
assert_equal(title, doc_from_string_enc.at('//title/text()').text)
|
129
129
|
assert_equal(title, doc_from_string.at('//title/text()').text)
|
130
130
|
assert_equal(title, doc_from_file_enc.at('//title/text()').text)
|
131
|
-
|
132
|
-
assert_equal(title, doc_from_file.at('//title/text()').text)
|
133
|
-
end
|
131
|
+
assert_equal(title, doc_from_file.at('//title/text()').text)
|
134
132
|
|
135
133
|
evil = (0..72).map { |i| '超' * i + '悪い事を構想中。' }
|
136
134
|
|
@@ -234,6 +234,9 @@ module Nokogiri
|
|
234
234
|
end
|
235
235
|
|
236
236
|
def test_element_children_counts
|
237
|
+
if Nokogiri.uses_libxml? && Nokogiri::VERSION_INFO['libxml']['loaded'] <= "2.9.1"
|
238
|
+
skip "#elements doesn't work in 2.9.1, see 1793a5a for history"
|
239
|
+
end
|
237
240
|
doc = Nokogiri::HTML::DocumentFragment.parse(" <div> </div>\n ")
|
238
241
|
assert_equal 1, doc.element_children.count
|
239
242
|
end
|
@@ -151,6 +151,54 @@ module Nokogiri
|
|
151
151
|
assert_equal "Gau\337", @parser.document.data.join
|
152
152
|
assert_equal [["r"]], @parser.document.end_elements
|
153
153
|
end
|
154
|
+
|
155
|
+
def test_replace_entities_attribute_behavior
|
156
|
+
if Nokogiri.uses_libxml?
|
157
|
+
# initially false
|
158
|
+
assert_equal false, @parser.replace_entities
|
159
|
+
|
160
|
+
# can be set to true
|
161
|
+
@parser.replace_entities = true
|
162
|
+
assert_equal true, @parser.replace_entities
|
163
|
+
|
164
|
+
# can be set to false
|
165
|
+
@parser.replace_entities = false
|
166
|
+
assert_equal false, @parser.replace_entities
|
167
|
+
else
|
168
|
+
# initially true
|
169
|
+
assert_equal true, @parser.replace_entities
|
170
|
+
|
171
|
+
# ignore attempts to set to false
|
172
|
+
@parser.replace_entities = false # TODO: should we raise an exception here?
|
173
|
+
assert_equal true, @parser.replace_entities
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_untouched_entities
|
178
|
+
skip("entities are always replaced in pure Java version") if Nokogiri.jruby?
|
179
|
+
@parser.<<(<<-eoxml)
|
180
|
+
<p id="asdf&asdf">
|
181
|
+
<!-- This is a comment -->
|
182
|
+
Paragraph 1 & 2
|
183
|
+
</p>
|
184
|
+
eoxml
|
185
|
+
@parser.finish
|
186
|
+
assert_equal [["p", [["id", "asdf&asdf"]]]], @parser.document.start_elements
|
187
|
+
assert_equal "Paragraph 1 & 2", @parser.document.data.join.strip
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_replaced_entities
|
191
|
+
@parser.replace_entities = true
|
192
|
+
@parser.<<(<<-eoxml)
|
193
|
+
<p id="asdf&asdf">
|
194
|
+
<!-- This is a comment -->
|
195
|
+
Paragraph 1 & 2
|
196
|
+
</p>
|
197
|
+
eoxml
|
198
|
+
@parser.finish
|
199
|
+
assert_equal [["p", [["id", "asdf&asdf"]]]], @parser.document.start_elements
|
200
|
+
assert_equal "Paragraph 1 & 2", @parser.document.data.join.strip
|
201
|
+
end
|
154
202
|
end
|
155
203
|
end
|
156
204
|
end
|
data/test/xml/test_attr.rb
CHANGED
@@ -11,6 +11,13 @@ module Nokogiri
|
|
11
11
|
}
|
12
12
|
end
|
13
13
|
|
14
|
+
def test_new_raises_argerror_on_nondocument
|
15
|
+
document = Nokogiri::XML "<root><foo/></root>"
|
16
|
+
assert_raises ArgumentError do
|
17
|
+
Nokogiri::XML::Attr.new document.at_css("foo"), "bar"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
14
21
|
def test_content=
|
15
22
|
xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
|
16
23
|
address = xml.xpath('//address')[3]
|
data/test/xml/test_document.rb
CHANGED
@@ -136,6 +136,23 @@ module Nokogiri
|
|
136
136
|
assert_equal expected, search_xpath
|
137
137
|
end
|
138
138
|
|
139
|
+
def test_fragment_css_search_with_whitespace_and_node_removal
|
140
|
+
# The same xml without leading whitespace in front of the first line
|
141
|
+
# does not expose the error. Putting both nodes on the same line
|
142
|
+
# instead also fixes the crash.
|
143
|
+
fragment = Nokogiri::XML::DocumentFragment.parse <<-EOXML
|
144
|
+
<p id="content">hi</p> x <!--y--> <p>another paragraph</p>
|
145
|
+
EOXML
|
146
|
+
children = fragment.css('p')
|
147
|
+
assert_equal 2, children.length
|
148
|
+
# removing the last node instead does not yield the error. Probably the
|
149
|
+
# node removal leaves around two consecutive text nodes which make the
|
150
|
+
# css search crash?
|
151
|
+
children.first.remove
|
152
|
+
assert_equal 1, fragment.xpath('.//p | self::p').length
|
153
|
+
assert_equal 1, fragment.css('p').length
|
154
|
+
end
|
155
|
+
|
139
156
|
def test_fragment_search_three_ways
|
140
157
|
frag = Nokogiri::XML::Document.new.fragment '<p id="content">foo</p><p id="content">bar</p>'
|
141
158
|
expected = frag.xpath('./*[@id = "content"]')
|
@@ -219,6 +236,16 @@ module Nokogiri
|
|
219
236
|
assert fragment.children.respond_to?(:awesome!), fragment.children.class
|
220
237
|
end
|
221
238
|
|
239
|
+
def test_decorator_is_applied_to_empty_set
|
240
|
+
x = Module.new do
|
241
|
+
def awesome!
|
242
|
+
end
|
243
|
+
end
|
244
|
+
util_decorate(@xml, x)
|
245
|
+
fragment = Nokogiri::XML::DocumentFragment.new(@xml, "")
|
246
|
+
assert fragment.children.respond_to?(:awesome!), fragment.children.class
|
247
|
+
end
|
248
|
+
|
222
249
|
def test_add_node_to_doc_fragment_segfault
|
223
250
|
frag = Nokogiri::XML::DocumentFragment.new(@xml, '<p>hello world</p>')
|
224
251
|
Nokogiri::XML::Comment.new(frag,'moo')
|
@@ -141,7 +141,7 @@ EOF
|
|
141
141
|
end
|
142
142
|
assert_kind_of Nokogiri::XML::EntityReference, doc.xpath('//body').first.children.first
|
143
143
|
if Nokogiri.uses_libxml?
|
144
|
-
assert_equal ["Entity 'bar' not defined"], doc.errors.map(&:to_s)
|
144
|
+
assert_equal ["5:14: ERROR: Entity 'bar' not defined"], doc.errors.map(&:to_s)
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
@@ -159,7 +159,7 @@ EOF
|
|
159
159
|
end
|
160
160
|
assert_kind_of Nokogiri::XML::EntityReference, doc.xpath('//body').first.children.first
|
161
161
|
if Nokogiri.uses_libxml?
|
162
|
-
assert_equal ["Attempt to load network entity http://foo.bar.com/", "Entity 'bar' not defined"], doc.errors.map(&:to_s)
|
162
|
+
assert_equal ["ERROR: Attempt to load network entity http://foo.bar.com/", "4:34: ERROR: Entity 'bar' not defined"], doc.errors.map(&:to_s)
|
163
163
|
else
|
164
164
|
assert_equal ["Attempt to load network entity http://foo.bar.com/"], doc.errors.map(&:to_s)
|
165
165
|
end
|