nokogiri 1.5.4.rc3-java → 1.5.5-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.

Files changed (39) hide show
  1. data/CHANGELOG.ja.rdoc +35 -18
  2. data/CHANGELOG.rdoc +22 -1
  3. data/README.ja.rdoc +5 -5
  4. data/README.rdoc +9 -9
  5. data/ROADMAP.md +20 -20
  6. data/Rakefile +16 -5
  7. data/Y_U_NO_GEMSPEC.md +3 -3
  8. data/ext/java/nokogiri/HtmlElementDescription.java +1 -1
  9. data/ext/java/nokogiri/HtmlEntityLookup.java +1 -1
  10. data/ext/java/nokogiri/XmlComment.java +14 -5
  11. data/ext/java/nokogiri/XmlElement.java +1 -59
  12. data/ext/java/nokogiri/XmlNode.java +71 -19
  13. data/ext/java/nokogiri/XmlNodeSet.java +1 -1
  14. data/ext/java/nokogiri/XmlReader.java +48 -15
  15. data/ext/java/nokogiri/XmlSyntaxError.java +9 -4
  16. data/ext/java/nokogiri/XmlXpathContext.java +8 -7
  17. data/ext/java/nokogiri/internals/NokogiriHandler.java +7 -1
  18. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +1 -5
  19. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +1 -1
  20. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +1 -1
  21. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +1 -1
  22. data/ext/java/nokogiri/internals/ParserContext.java +65 -104
  23. data/ext/java/nokogiri/internals/XmlDeclHandler.java +1 -1
  24. data/ext/java/nokogiri/internals/XmlDomParser.java +4 -6
  25. data/ext/java/nokogiri/internals/XmlDomParserContext.java +15 -12
  26. data/ext/nokogiri/xml_node.c +2 -2
  27. data/lib/nokogiri/css/parser.rb +75 -79
  28. data/lib/nokogiri/html/document.rb +1 -1
  29. data/lib/nokogiri/nokogiri.jar +0 -0
  30. data/lib/nokogiri/version.rb +1 -1
  31. data/lib/nokogiri/xml/node.rb +1 -1
  32. data/lib/nokogiri/xml/node/save_options.rb +1 -1
  33. data/test/html/test_document.rb +17 -0
  34. data/test/xml/test_document.rb +1 -1
  35. data/test/xml/test_dtd.rb +3 -7
  36. data/test/xml/test_entity_reference.rb +214 -0
  37. data/test/xml/test_node_reparenting.rb +9 -1
  38. data/test/xml/test_xpath.rb +28 -1
  39. metadata +17 -26
@@ -180,7 +180,7 @@ module Nokogiri
180
180
  m = chunk.match(/(<meta\s)(.*)(charset\s*=\s*([\w-]+))(.*)/i) and
181
181
  return m[4]
182
182
  catch(:encoding_found) {
183
- Nokogiri::HTML::SAX::Parser.new(JumpSAXHandler.new(:encoding_found.to_s)).parse(chunk)
183
+ Nokogiri::HTML::SAX::Parser.new(JumpSAXHandler.new(:encoding_found)).parse(chunk)
184
184
  nil
185
185
  }
186
186
  else
Binary file
@@ -1,6 +1,6 @@
1
1
  module Nokogiri
2
2
  # The version of Nokogiri you are using
3
- VERSION = '1.5.4.rc3'
3
+ VERSION = '1.5.5'
4
4
 
5
5
  class VersionInfo # :nodoc:
6
6
  def jruby?
@@ -150,7 +150,7 @@ module Nokogiri
150
150
  sets = paths.map { |path|
151
151
  ctx = XPathContext.new(self)
152
152
  ctx.register_namespaces(ns)
153
- path = path.gsub(/\/xmlns:/,'/:') unless Nokogiri.uses_libxml?
153
+ path = path.gsub(/xmlns:/, ' :') unless Nokogiri.uses_libxml?
154
154
 
155
155
  binds.each do |key,value|
156
156
  ctx.register_variable key.to_s, value
@@ -23,7 +23,7 @@ module Nokogiri
23
23
  # Save builder created document
24
24
  AS_BUILDER = 128
25
25
  # the default for XML documents
26
- DEFAULT_XML = AS_XML # https://github.com/tenderlove/nokogiri/issues/#issue/415
26
+ DEFAULT_XML = AS_XML # https://github.com/sparklemotion/nokogiri/issues/#issue/415
27
27
  # the default for HTML document
28
28
  DEFAULT_HTML = NO_DECLARATION | NO_EMPTY_TAGS | AS_HTML
29
29
  else
@@ -85,6 +85,17 @@ module Nokogiri
85
85
  assert_equal @html.to_s, html.to_s
86
86
  end
87
87
 
88
+ def test_document_parse_method_with_url
89
+ require 'open-uri'
90
+ begin
91
+ html = open('http://google.com').read
92
+ rescue
93
+ skip("This test needs the internet. Skips if no internet available.")
94
+ end
95
+ doc = Nokogiri::HTML html ,"http:/foobar.foobar/"
96
+ refute_empty doc.to_s, "Document should not be empty"
97
+ end
98
+
88
99
  ###
89
100
  # Nokogiri::HTML returns an empty Document when given a blank string GH#11
90
101
  def test_empty_string_returns_empty_doc
@@ -506,6 +517,12 @@ eohtml
506
517
  assert @html.serialize
507
518
  assert @html.to_html
508
519
  end
520
+
521
+ def test_empty_document
522
+ # empty document should return "" #699
523
+ assert_equal "", Nokogiri::HTML.parse(nil).text
524
+ assert_equal "", Nokogiri::HTML.parse("").text
525
+ end
509
526
  end
510
527
  end
511
528
  end
@@ -268,7 +268,7 @@ module Nokogiri
268
268
  assert_equal 44, @xml.validate.length
269
269
  else
270
270
  xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) {|cfg| cfg.dtdvalid}
271
- assert_equal 37, xml.validate.length
271
+ assert_equal 40, xml.validate.length
272
272
  end
273
273
  end
274
274
 
@@ -14,12 +14,8 @@ module Nokogiri
14
14
  end
15
15
 
16
16
  def test_external_id
17
- if Nokogiri.uses_libxml?
18
- xml = Nokogiri::XML('<!DOCTYPE foo PUBLIC "bar"><foo />')
19
- else
20
- xml = Nokogiri::XML('<!DOCTYPE foo PUBLIC "bar" ""><foo />')
21
- end
22
- assert dtd = xml.internal_subset
17
+ xml = Nokogiri::XML('<!DOCTYPE foo PUBLIC "bar" ""><foo />')
18
+ assert dtd = xml.internal_subset, 'no internal subset'
23
19
  assert_equal 'bar', dtd.external_id
24
20
  end
25
21
 
@@ -74,7 +70,7 @@ module Nokogiri
74
70
  else
75
71
  xml = Nokogiri::XML(File.open(XML_FILE)) {|cfg| cfg.dtdvalid}
76
72
  list = xml.internal_subset.validate xml
77
- assert_equal 37, list.length
73
+ assert_equal 40, list.length
78
74
  end
79
75
  end
80
76
 
@@ -17,5 +17,219 @@ module Nokogiri
17
17
  100.times { EntityReference.new(@xml, 'foo') }
18
18
  end
19
19
  end
20
+
21
+ module Common
22
+ PATH = 'test/files/test_document_url/'
23
+
24
+ attr_accessor :path, :parser
25
+
26
+ def xml_document
27
+ File.join path, 'document.xml'
28
+ end
29
+
30
+ def self.included base
31
+ def base.test_relative_and_absolute_path method_name, &block
32
+ test_relative_path method_name, &block
33
+ test_absolute_path method_name, &block
34
+ end
35
+
36
+ def base.test_absolute_path method_name, &block
37
+ define_method "#{method_name}_with_absolute_path" do
38
+ self.path = "#{File.expand_path PATH}/"
39
+ instance_eval(&block)
40
+ end
41
+ end
42
+
43
+ def base.test_relative_path method_name, &block
44
+ define_method method_name do
45
+ self.path = PATH
46
+ instance_eval(&block)
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ class TestDOMEntityReference < Nokogiri::TestCase
53
+ include Common
54
+
55
+ def setup
56
+ super
57
+ @parser = Nokogiri::XML::Document
58
+ end
59
+
60
+ test_relative_and_absolute_path :test_dom_entity_reference_with_dtdloda do
61
+ # Make sure that we can parse entity references and include them in the document
62
+ html = File.read xml_document
63
+ doc = @parser.parse html, path do |cfg|
64
+ cfg.default_xml
65
+ cfg.dtdload
66
+ cfg.noent
67
+ end
68
+ assert_equal [], doc.errors
69
+ assert_equal "foobar", doc.xpath('//blah').text
70
+ end
71
+
72
+ test_relative_and_absolute_path :test_dom_entity_reference_with_dtdvalid do
73
+ # Make sure that we can parse entity references and include them in the document
74
+ html = File.read xml_document
75
+ doc = @parser.parse html, path do |cfg|
76
+ cfg.default_xml
77
+ cfg.dtdvalid
78
+ cfg.noent
79
+ end
80
+ assert_equal [], doc.errors
81
+ assert_equal "foobar", doc.xpath('//blah').text
82
+ end
83
+
84
+ test_absolute_path :test_dom_dtd_loading_with_absolute_path do
85
+ # Make sure that we can parse entity references and include them in the document
86
+ html = %Q[<?xml version="1.0" encoding="UTF-8" ?>
87
+ <!DOCTYPE document SYSTEM "#{path}/document.dtd">
88
+ <document>
89
+ <body>&bar;</body>
90
+ </document>
91
+ ]
92
+ doc = @parser.parse html, xml_document do |cfg|
93
+ cfg.default_xml
94
+ cfg.dtdvalid
95
+ cfg.noent
96
+ end
97
+ assert_equal [], doc.errors
98
+ assert_equal "foobar", doc.xpath('//blah').text
99
+ end
100
+
101
+ test_relative_and_absolute_path :test_dom_entity_reference_with_io do
102
+ # Make sure that we can parse entity references and include them in the document
103
+ html = File.open xml_document
104
+ doc = @parser.parse html, nil do |cfg|
105
+ cfg.default_xml
106
+ cfg.dtdload
107
+ cfg.noent
108
+ end
109
+ assert_equal [], doc.errors
110
+ assert_equal "foobar", doc.xpath('//blah').text
111
+ end
112
+
113
+ test_relative_and_absolute_path :test_dom_entity_reference_without_noent do
114
+ # Make sure that we don't include entity references unless NOENT is set to true
115
+ html = File.read xml_document
116
+ doc = @parser.parse html, path do |cfg|
117
+ cfg.default_xml
118
+ cfg.dtdload
119
+ end
120
+ assert_equal [], doc.errors
121
+ assert_kind_of Nokogiri::XML::EntityReference, doc.xpath('//body').first.children.first
122
+ end
123
+
124
+ test_relative_and_absolute_path :test_dom_entity_reference_without_dtdload do
125
+ # Make sure that we don't include entity references unless NOENT is set to true
126
+ html = File.read xml_document
127
+ doc = @parser.parse html, path do |cfg|
128
+ cfg.default_xml
129
+ end
130
+ assert_kind_of Nokogiri::XML::EntityReference, doc.xpath('//body').first.children.first
131
+ if Nokogiri.uses_libxml?
132
+ assert_equal ["Entity 'bar' not defined"], doc.errors.map(&:to_s)
133
+ end
134
+ end
135
+
136
+ test_relative_and_absolute_path :test_document_dtd_loading_with_nonet do
137
+ # Make sure that we don't include remote entities unless NOENT is set to true
138
+ html = %Q[<?xml version="1.0" encoding="UTF-8" ?>
139
+ <!DOCTYPE document SYSTEM "http://foo.bar.com/">
140
+ <document>
141
+ <body>&bar;</body>
142
+ </document>
143
+ ]
144
+ doc = @parser.parse html, path do |cfg|
145
+ cfg.default_xml
146
+ cfg.dtdload
147
+ end
148
+ assert_kind_of Nokogiri::XML::EntityReference, doc.xpath('//body').first.children.first
149
+ if Nokogiri.uses_libxml?
150
+ assert_equal ["Attempt to load network entity http://foo.bar.com/", "Entity 'bar' not defined"], doc.errors.map(&:to_s)
151
+ else
152
+ assert_equal ["Attempt to load network entity http://foo.bar.com/"], doc.errors.map(&:to_s)
153
+ end
154
+ end
155
+ # TODO: can we retreive a resource pointing to localhost when NONET is set to true ?
156
+ end
157
+
158
+ class TestSaxEntityReference < Nokogiri::SAX::TestCase
159
+ include Common
160
+
161
+ def setup
162
+ super
163
+ @parser = XML::SAX::Parser.new(Doc.new) do |ctx|
164
+ ctx.replace_entities = true
165
+ end
166
+ end
167
+
168
+ test_relative_and_absolute_path :test_sax_entity_reference do
169
+ # Make sure that we can parse entity references and include them in the document
170
+ html = File.read xml_document
171
+ @parser.parse html
172
+ refute_nil @parser.document.errors
173
+ assert_equal ["Entity 'bar' not defined"], @parser.document.errors.map(&:to_s).map(&:strip)
174
+ end
175
+
176
+ test_relative_and_absolute_path :test_more_sax_entity_reference do
177
+ # Make sure that we don't include entity references unless NOENT is set to true
178
+ html = %Q[<?xml version="1.0" encoding="UTF-8" ?>
179
+ <!DOCTYPE document SYSTEM "http://foo.bar.com/">
180
+ <document>
181
+ <body>&bar;</body>
182
+ </document>
183
+ ]
184
+ @parser.parse html
185
+ refute_nil @parser.document.errors
186
+ assert_equal ["Entity 'bar' not defined"], @parser.document.errors.map(&:to_s).map(&:strip)
187
+ end
188
+ end
189
+
190
+ class TestReaderEntityReference < Nokogiri::TestCase
191
+ include Common
192
+
193
+ def setup
194
+ super
195
+ end
196
+
197
+ test_relative_and_absolute_path :test_reader_entity_reference do
198
+ # Make sure that we can parse entity references and include them in the document
199
+ html = File.read xml_document
200
+ reader = Nokogiri::XML::Reader html, path do |cfg|
201
+ cfg.default_xml
202
+ cfg.dtdload
203
+ cfg.noent
204
+ end
205
+ nodes = []
206
+ reader.each { |n| nodes << n.value }
207
+ assert_equal ['foobar'], nodes.compact.map(&:strip).reject(&:empty?)
208
+ end
209
+
210
+ test_relative_and_absolute_path :test_reader_entity_reference_without_noent do
211
+ # Make sure that we can parse entity references and include them in the document
212
+ html = File.read xml_document
213
+ reader = Nokogiri::XML::Reader html, path do |cfg|
214
+ cfg.default_xml
215
+ cfg.dtdload
216
+ end
217
+ nodes = []
218
+ reader.each { |n| nodes << n.value }
219
+ assert_equal [], nodes.compact.map(&:strip).reject(&:empty?)
220
+ end
221
+
222
+ test_relative_and_absolute_path :test_reader_entity_reference_without_dtdload do
223
+ # Make sure that we can parse entity references and include them in the document
224
+ html = File.read xml_document
225
+ assert_raises(Nokogiri::XML::SyntaxError) do
226
+ reader = Nokogiri::XML::Reader html, path do |cfg|
227
+ cfg.default_xml
228
+ end
229
+ nodes = []
230
+ reader.each { |n| nodes << n.value }
231
+ end
232
+ end
233
+ end
20
234
  end
21
235
  end
@@ -156,6 +156,7 @@ module Nokogiri
156
156
  @doc.at_xpath("/root/a1/text()").content.must_equal "First nodehello"
157
157
  end
158
158
  end
159
+
159
160
  describe "#replace" do
160
161
  it "merges the Text node with adjacent Text nodes" do
161
162
  @doc.at_xpath("/root/a3/bx").replace Nokogiri::XML::Text.new('hello', @doc)
@@ -247,6 +248,13 @@ module Nokogiri
247
248
  assert_equal "foo <p></p> bartext node", xml.root.children.to_html
248
249
  end
249
250
 
251
+ it 'should remove the child node after the operation' do
252
+ fragment = Nokogiri::HTML::DocumentFragment.parse("a<a>b</a>")
253
+ node = fragment.children.last
254
+ node.add_previous_sibling node.children
255
+ assert_empty node.children, "should have no childrens"
256
+ end
257
+
250
258
  describe "with a text node before" do
251
259
  it "should not defensively dup the 'before' text node" do
252
260
  xml = Nokogiri::XML %Q(<root>before<p></p>after</root>)
@@ -321,7 +329,7 @@ module Nokogiri
321
329
 
322
330
  describe "unlinking a node and then reparenting it" do
323
331
  it "not blow up" do
324
- # see http://github.com/tenderlove/nokogiri/issues#issue/22
332
+ # see http://github.com/sparklemotion/nokogiri/issues#issue/22
325
333
  10.times do
326
334
  begin
327
335
  doc = Nokogiri::XML <<-EOHTML
@@ -217,7 +217,7 @@ module Nokogiri
217
217
  end
218
218
 
219
219
  def test_custom_xpath_handler_with_args_under_gc_pressure
220
- # see http://github.com/tenderlove/nokogiri/issues/#issue/345
220
+ # see http://github.com/sparklemotion/nokogiri/issues/#issue/345
221
221
  tool_inspector = Class.new do
222
222
  def name_equals(nodeset, name, *args)
223
223
  nodeset.all? do |node|
@@ -263,6 +263,33 @@ module Nokogiri
263
263
  }.new)
264
264
  assert_equal foo, doc.xpath("//foo")
265
265
  end
266
+
267
+ def test_node_set_should_be_decorated
268
+ # "called decorate on nill" exception in JRuby issue#514
269
+ process_output= <<END
270
+ <test>
271
+ <track type="Image">
272
+ <Format>LZ77</Format>
273
+ </test>
274
+ END
275
+ doc = Nokogiri::XML.parse(process_output)
276
+ node = doc.xpath(%{//track[@type='Video']})
277
+ assert_equal "[]", node.xpath("Format").inspect
278
+ end
279
+
280
+ def test_very_specific_xml_xpath_making_problems_in_jruby
281
+ # manually merges pull request #681
282
+ xml_string = %q{<?xml version="1.0" encoding="UTF-8"?>
283
+ <ONIXMessage xmlns:elibri="http://elibri.com.pl/ns/extensions" release="3.0" xmlns="http://www.editeur.org/onix/3.0/reference">
284
+ <Product>
285
+ <RecordReference>a</RecordReference>
286
+ </Product>
287
+ </ONIXMessage>}
288
+
289
+ xml_doc = Nokogiri::XML(xml_string)
290
+ onix = xml_doc.children.first
291
+ assert_equal 'a', onix.at_xpath('xmlns:Product').at_xpath('xmlns:RecordReference').text
292
+ end
266
293
  end
267
294
  end
268
295
  end
metadata CHANGED
@@ -1,18 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: 6
5
- version: 1.5.4.rc3
4
+ prerelease:
5
+ version: 1.5.5
6
6
  platform: java
7
7
  authors:
8
8
  - Aaron Patterson
9
9
  - Mike Dalessio
10
10
  - Yoko Harada
11
+ - Tim Elliott
11
12
  autorequire:
12
13
  bindir: bin
13
14
  cert_chain: []
14
15
 
15
- date: 2012-06-08 00:00:00 Z
16
+ date: 2012-06-23 00:00:00 Z
16
17
  dependencies:
17
18
  - !ruby/object:Gem::Dependency
18
19
  name: hoe-bundler
@@ -81,13 +82,13 @@ dependencies:
81
82
  prerelease: false
82
83
  type: :development
83
84
  - !ruby/object:Gem::Dependency
84
- name: racc
85
+ name: rake
85
86
  version_requirements: &id007 !ruby/object:Gem::Requirement
86
87
  none: false
87
88
  requirements:
88
89
  - - ">="
89
90
  - !ruby/object:Gem::Version
90
- version: 1.4.6
91
+ version: "0.9"
91
92
  requirement: *id007
92
93
  prerelease: false
93
94
  type: :development
@@ -102,37 +103,26 @@ dependencies:
102
103
  requirement: *id008
103
104
  prerelease: false
104
105
  type: :development
105
- - !ruby/object:Gem::Dependency
106
- name: rexical
107
- version_requirements: &id009 !ruby/object:Gem::Requirement
108
- none: false
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: 1.0.5
113
- requirement: *id009
114
- prerelease: false
115
- type: :development
116
106
  - !ruby/object:Gem::Dependency
117
107
  name: rdoc
118
- version_requirements: &id010 !ruby/object:Gem::Requirement
108
+ version_requirements: &id009 !ruby/object:Gem::Requirement
119
109
  none: false
120
110
  requirements:
121
111
  - - ~>
122
112
  - !ruby/object:Gem::Version
123
113
  version: "3.10"
124
- requirement: *id010
114
+ requirement: *id009
125
115
  prerelease: false
126
116
  type: :development
127
117
  - !ruby/object:Gem::Dependency
128
118
  name: hoe
129
- version_requirements: &id011 !ruby/object:Gem::Requirement
119
+ version_requirements: &id010 !ruby/object:Gem::Requirement
130
120
  none: false
131
121
  requirements:
132
122
  - - ~>
133
123
  - !ruby/object:Gem::Version
134
- version: "2.13"
135
- requirement: *id011
124
+ version: "2.16"
125
+ requirement: *id010
136
126
  prerelease: false
137
127
  type: :development
138
128
  description: "Nokogiri (\xE9\x8B\xB8) is an HTML, XML, SAX, and Reader parser. Among Nokogiri's\n\
@@ -143,17 +133,18 @@ email:
143
133
  - aaronp@rubyforge.org
144
134
  - mike.dalessio@gmail.com
145
135
  - yokolet@gmail.com
136
+ - tle@holymonkey.com
146
137
  executables:
147
138
  - nokogiri
148
139
  extensions: []
149
140
 
150
141
  extra_rdoc_files:
151
- - Manifest.txt
152
142
  - CHANGELOG.ja.rdoc
143
+ - CHANGELOG.rdoc
144
+ - C_CODING_STYLE.rdoc
145
+ - Manifest.txt
153
146
  - README.ja.rdoc
154
147
  - README.rdoc
155
- - C_CODING_STYLE.rdoc
156
- - CHANGELOG.rdoc
157
148
  - ext/nokogiri/xml_encoding_handler.c
158
149
  - ext/nokogiri/html_sax_push_parser.c
159
150
  - ext/nokogiri/xml_processing_instruction.c
@@ -506,9 +497,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
506
497
  required_rubygems_version: !ruby/object:Gem::Requirement
507
498
  none: false
508
499
  requirements:
509
- - - ">"
500
+ - - ">="
510
501
  - !ruby/object:Gem::Version
511
- version: 1.3.1
502
+ version: "0"
512
503
  requirements: []
513
504
 
514
505
  rubyforge_project: nokogiri