nokogiri 1.4.2-java → 1.4.3-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 (56) hide show
  1. data/CHANGELOG.ja.rdoc +28 -8
  2. data/CHANGELOG.rdoc +24 -1
  3. data/Manifest.txt +2 -1
  4. data/README.ja.rdoc +1 -1
  5. data/README.rdoc +22 -4
  6. data/Rakefile +6 -2
  7. data/ext/nokogiri/extconf.rb +55 -32
  8. data/ext/nokogiri/nokogiri.h +2 -0
  9. data/ext/nokogiri/xml_document.c +5 -0
  10. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  11. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  12. data/ext/nokogiri/xml_node.c +58 -12
  13. data/ext/nokogiri/xml_node_set.c +7 -7
  14. data/ext/nokogiri/xml_reader.c +20 -1
  15. data/ext/nokogiri/xml_xpath_context.c +2 -0
  16. data/lib/nokogiri/css/generated_parser.rb +155 -148
  17. data/lib/nokogiri/css/generated_tokenizer.rb +2 -1
  18. data/lib/nokogiri/css/parser.y +3 -0
  19. data/lib/nokogiri/css/xpath_visitor.rb +1 -7
  20. data/lib/nokogiri/ffi/libxml.rb +29 -4
  21. data/lib/nokogiri/ffi/xml/document.rb +4 -0
  22. data/lib/nokogiri/ffi/xml/node.rb +27 -19
  23. data/lib/nokogiri/ffi/xml/node_set.rb +3 -3
  24. data/lib/nokogiri/ffi/xml/reader.rb +4 -0
  25. data/lib/nokogiri/html.rb +2 -2
  26. data/lib/nokogiri/html/document_fragment.rb +7 -4
  27. data/lib/nokogiri/version.rb +2 -1
  28. data/lib/nokogiri/xml/builder.rb +1 -1
  29. data/lib/nokogiri/xml/document.rb +1 -2
  30. data/lib/nokogiri/xml/document_fragment.rb +7 -0
  31. data/lib/nokogiri/xml/node.rb +4 -2
  32. data/lib/nokogiri/xml/node_set.rb +25 -0
  33. data/lib/nokogiri/xml/reader.rb +2 -0
  34. data/lib/nokogiri/xml/sax/document.rb +3 -1
  35. data/tasks/cross_compile.rb +7 -6
  36. data/test/css/test_parser.rb +11 -1
  37. data/test/html/sax/test_parser_context.rb +2 -2
  38. data/test/html/test_document.rb +2 -2
  39. data/test/html/test_document_fragment.rb +34 -6
  40. data/test/test_memory_leak.rb +2 -2
  41. data/test/test_reader.rb +28 -6
  42. data/test/test_xslt_transforms.rb +29 -28
  43. data/test/xml/test_attr.rb +31 -4
  44. data/test/xml/test_builder.rb +5 -5
  45. data/test/xml/test_cdata.rb +3 -3
  46. data/test/xml/test_document.rb +8 -8
  47. data/test/xml/test_document_fragment.rb +2 -2
  48. data/test/xml/test_node.rb +1 -1
  49. data/test/xml/test_node_reparenting.rb +26 -11
  50. data/test/xml/test_node_set.rb +38 -2
  51. data/test/xml/test_text.rb +11 -2
  52. data/test/xml/test_unparented_node.rb +1 -1
  53. data/test/xml/test_xpath.rb +78 -11
  54. metadata +26 -6
  55. data/lib/nokogiri/nokogiri.rb +0 -1
  56. data/lib/nokogiri/version_warning.rb +0 -14
@@ -3,6 +3,27 @@ require "helper"
3
3
  module Nokogiri
4
4
  module XML
5
5
  class TestNodeSet < Nokogiri::TestCase
6
+ class TestNodeSetNamespaces < Nokogiri::TestCase
7
+ def setup
8
+ super
9
+ @xml = Nokogiri.XML('<foo xmlns:n0="http://example.com" />')
10
+ @list = @xml.xpath('//namespace::*')
11
+ end
12
+
13
+ def test_include?
14
+ assert @list.include?(@list.first), 'list should have item'
15
+ end
16
+
17
+ def test_push
18
+ @list.push @list.first
19
+ end
20
+
21
+ def test_delete
22
+ @list.push @list.first
23
+ @list.delete @list.first
24
+ end
25
+ end
26
+
6
27
  def setup
7
28
  super
8
29
  @xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
@@ -255,11 +276,26 @@ module Nokogiri
255
276
  assert_match '<a>', html
256
277
  end
257
278
 
279
+ def test_gt_string_arg
280
+ assert node_set = @xml.search('//employee')
281
+ assert_equal node_set.xpath('./employeeId'), (node_set > 'employeeId')
282
+ end
283
+
258
284
  def test_at
259
285
  assert node_set = @xml.search('//employee')
260
286
  assert_equal node_set.first, node_set.at(0)
261
287
  end
262
288
 
289
+ def test_at_xpath
290
+ assert node_set = @xml.search('//employee')
291
+ assert_equal node_set.first.first_element_child, node_set.at_xpath('./employeeId')
292
+ end
293
+
294
+ def test_at_css
295
+ assert node_set = @xml.search('//employee')
296
+ assert_equal node_set.first.first_element_child, node_set.at_css('employeeId')
297
+ end
298
+
263
299
  def test_percent
264
300
  assert node_set = @xml.search('//employee')
265
301
  assert_equal node_set.first, node_set % 0
@@ -410,7 +446,7 @@ module Nokogiri
410
446
  names_len = names.length
411
447
  positions_len = positions.length
412
448
 
413
- assert_raises(ArgumentError) { result = names + positions.first }
449
+ assert_raises(ArgumentError) { names + positions.first }
414
450
 
415
451
  result = names + positions
416
452
  assert_equal names_len, names.length
@@ -434,7 +470,7 @@ module Nokogiri
434
470
  employees_len = employees.length
435
471
  females_len = females.length
436
472
 
437
- assert_raises(ArgumentError) { result = employees - females.first }
473
+ assert_raises(ArgumentError) { employees - females.first }
438
474
 
439
475
  result = employees - females
440
476
  assert_equal employees_len, employees.length
@@ -3,6 +3,13 @@ require "helper"
3
3
  module Nokogiri
4
4
  module XML
5
5
  class TestText < Nokogiri::TestCase
6
+ def test_css_path
7
+ doc = Nokogiri.XML "<root> foo <a>something</a> bar bazz </root>"
8
+ node = doc.root.children[2]
9
+ assert_instance_of Nokogiri::XML::Text, node
10
+ assert_equal node, doc.at_css(node.css_path)
11
+ end
12
+
6
13
  def test_inspect
7
14
  node = Text.new('hello world', Document.new)
8
15
  assert_equal "#<#{node.class.name}:#{sprintf("0x%x",node.object_id)} #{node.text.inspect}>", node.inspect
@@ -19,11 +26,13 @@ module Nokogiri
19
26
  100.times { Text.new('hello world', Document.new) }
20
27
  end
21
28
 
22
- # No assertion because this was a segv
23
29
  def test_new_without_document
24
30
  doc = Document.new
25
31
  node = Nokogiri::XML::Element.new('foo', doc)
26
- text = Text.new('hello world', node)
32
+
33
+ assert_nothing_raised do
34
+ Text.new('hello world', node)
35
+ end
27
36
  end
28
37
 
29
38
  def test_content=
@@ -129,7 +129,7 @@ module Nokogiri
129
129
  def test_add_child_in_same_document
130
130
  child = @node.css('employee').first
131
131
 
132
- assert previous_last_child = child.children.last
132
+ assert child.children.last
133
133
  assert new_child = child.children.first
134
134
 
135
135
  last = child.children.last
@@ -3,10 +3,37 @@ require "helper"
3
3
  module Nokogiri
4
4
  module XML
5
5
  class TestXPath < Nokogiri::TestCase
6
+
7
+ # ** WHY ALL THOSE _if Nokogiri.uses_libxml?_ **
8
+ # Hi, my dear readers,
9
+ #
10
+ # After reading these tests you may be wondering why all those ugly
11
+ # if Nokogiri.uses_libxml? sparsed over the whole document. Well, let
12
+ # me explain it. While using XPath in Java, you need the extension
13
+ # functions to be in a namespace. This is not required by XPath, afaik,
14
+ # but it is an usual convention though.
15
+ #
16
+ # Furthermore, CSS does not support extension functions but it does in
17
+ # Nokogiri. Result: you cannot use them in JRuby impl. At least, until
18
+ # the CSS to XPath parser is patched, and let me say that there are more
19
+ # important features to add before that happens. I hope you will forgive
20
+ # me.
21
+ #
22
+ # Yours truly,
23
+ #
24
+ # The guy whose headaches belong to Nokogiri JRuby impl.
25
+
26
+
6
27
  def setup
7
28
  super
29
+
8
30
  @xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
9
31
 
32
+ @ns = @xml.root.namespaces
33
+
34
+ # TODO: Maybe I should move this to the original code.
35
+ @ns["nokogiri"] = "http://www.nokogiri.org/default_ns/ruby/extensions_functions"
36
+
10
37
  @handler = Class.new {
11
38
  attr_reader :things
12
39
 
@@ -52,7 +79,11 @@ module Nokogiri
52
79
  end
53
80
 
54
81
  def test_css_search_uses_custom_selectors_with_arguments
55
- set = @xml.css('employee > address:my_filter("domestic", "Yes")', @handler)
82
+ set = if Nokogiri.uses_libxml?
83
+ @xml.css('employee > address:my_filter("domestic", "Yes")', @handler)
84
+ else
85
+ @xml.xpath("//employee/address[nokogiri:my_filter(., \"domestic\", \"Yes\")]", @ns, @handler)
86
+ end
56
87
  assert set.length > 0
57
88
  set.each do |node|
58
89
  assert_equal 'Yes', node['domestic']
@@ -61,13 +92,23 @@ module Nokogiri
61
92
 
62
93
  def test_css_search_uses_custom_selectors
63
94
  set = @xml.xpath('//employee')
64
- css_set = @xml.css('employee:thing()', @handler)
95
+ assert_nothing_raised do
96
+ if Nokogiri.uses_libxml?
97
+ @xml.css('employee:thing()', @handler)
98
+ else
99
+ @xml.xpath("//employee[nokogiri:thing(.)]", @ns, @handler)
100
+ end
101
+ end
65
102
  assert_equal(set.length, @handler.things.length)
66
103
  assert_equal(set.to_a, @handler.things.flatten)
67
104
  end
68
105
 
69
106
  def test_pass_self_to_function
70
- set = @xml.xpath('//employee/address[my_filter(., "domestic", "Yes")]', @handler)
107
+ set = if Nokogiri.uses_libxml?
108
+ @xml.xpath('//employee/address[my_filter(., "domestic", "Yes")]', @handler)
109
+ else
110
+ @xml.xpath('//employee/address[nokogiri:my_filter(., "domestic", "Yes")]', @ns, @handler)
111
+ end
71
112
  assert set.length > 0
72
113
  set.each do |node|
73
114
  assert_equal 'Yes', node['domestic']
@@ -76,42 +117,66 @@ module Nokogiri
76
117
 
77
118
  def test_custom_xpath_function_gets_strings
78
119
  set = @xml.xpath('//employee')
79
- @xml.xpath('//employee[thing("asdf")]', @handler)
120
+ if Nokogiri.uses_libxml?
121
+ @xml.xpath('//employee[thing("asdf")]', @handler)
122
+ else
123
+ @xml.xpath('//employee[nokogiri:thing("asdf")]', @ns, @handler)
124
+ end
80
125
  assert_equal(set.length, @handler.things.length)
81
126
  assert_equal(['asdf'] * set.length, @handler.things)
82
127
  end
83
128
 
84
129
  def test_custom_xpath_gets_true_booleans
85
130
  set = @xml.xpath('//employee')
86
- @xml.xpath('//employee[thing(true())]', @handler)
131
+ if Nokogiri.uses_libxml?
132
+ @xml.xpath('//employee[thing(true())]', @handler)
133
+ else
134
+ @xml.xpath("//employee[nokogiri:thing(true())]", @ns, @handler)
135
+ end
87
136
  assert_equal(set.length, @handler.things.length)
88
137
  assert_equal([true] * set.length, @handler.things)
89
138
  end
90
139
 
91
140
  def test_custom_xpath_gets_false_booleans
92
141
  set = @xml.xpath('//employee')
93
- @xml.xpath('//employee[thing(false())]', @handler)
142
+ if Nokogiri.uses_libxml?
143
+ @xml.xpath('//employee[thing(false())]', @handler)
144
+ else
145
+ @xml.xpath("//employee[nokogiri:thing(false())]", @ns, @handler)
146
+ end
94
147
  assert_equal(set.length, @handler.things.length)
95
148
  assert_equal([false] * set.length, @handler.things)
96
149
  end
97
150
 
98
151
  def test_custom_xpath_gets_numbers
99
152
  set = @xml.xpath('//employee')
100
- @xml.xpath('//employee[thing(10)]', @handler)
153
+ if Nokogiri.uses_libxml?
154
+ @xml.xpath('//employee[thing(10)]', @handler)
155
+ else
156
+ @xml.xpath('//employee[nokogiri:thing(10)]', @ns, @handler)
157
+ end
101
158
  assert_equal(set.length, @handler.things.length)
102
159
  assert_equal([10] * set.length, @handler.things)
103
160
  end
104
161
 
105
162
  def test_custom_xpath_gets_node_sets
106
163
  set = @xml.xpath('//employee/name')
107
- @xml.xpath('//employee[thing(name)]', @handler)
164
+ if Nokogiri.uses_libxml?
165
+ @xml.xpath('//employee[thing(name)]', @handler)
166
+ else
167
+ @xml.xpath('//employee[nokogiri:thing(name)]', @ns, @handler)
168
+ end
108
169
  assert_equal(set.length, @handler.things.length)
109
170
  assert_equal(set.to_a, @handler.things.flatten)
110
171
  end
111
172
 
112
173
  def test_custom_xpath_gets_node_sets_and_returns_array
113
174
  set = @xml.xpath('//employee/name')
114
- @xml.xpath('//employee[returns_array(name)]', @handler)
175
+ if Nokogiri.uses_libxml?
176
+ @xml.xpath('//employee[returns_array(name)]', @handler)
177
+ else
178
+ @xml.xpath('//employee[nokogiri:returns_array(name)]', @ns, @handler)
179
+ end
115
180
  assert_equal(set.length, @handler.things.length)
116
181
  assert_equal(set.to_a, @handler.things.flatten)
117
182
  end
@@ -121,7 +186,9 @@ module Nokogiri
121
186
  def awesome! ; end
122
187
  end
123
188
  util_decorate(@xml, x)
124
- set = @xml.xpath('//employee/name')
189
+
190
+ assert @xml.xpath('//employee/name')
191
+
125
192
  @xml.xpath('//employee[saves_node_set(name)]', @handler)
126
193
  assert_equal @xml, @handler.things.document
127
194
  assert @handler.things.respond_to?(:awesome!)
@@ -131,7 +198,7 @@ module Nokogiri
131
198
  doc = "<html><body id='foo'><foo>hi</foo></body></html>"
132
199
  xpath = 'id("foo")//foo'
133
200
  nokogiri = Nokogiri::HTML.parse(doc)
134
- tree = nokogiri.xpath(xpath)
201
+ assert nokogiri.xpath(xpath)
135
202
  end
136
203
  end
137
204
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 1
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
8
  - 4
8
- - 2
9
- version: 1.4.2
9
+ - 3
10
+ version: 1.4.3
10
11
  platform: java
11
12
  authors:
12
13
  - Aaron Patterson
@@ -15,16 +16,18 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-05-22 00:00:00 -04:00
19
+ date: 2010-07-28 00:00:00 -07:00
19
20
  default_executable: nokogiri
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
23
  name: rubyforge
23
24
  prerelease: false
24
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
25
27
  requirements:
26
28
  - - ">="
27
29
  - !ruby/object:Gem::Version
30
+ hash: 7
28
31
  segments:
29
32
  - 2
30
33
  - 0
@@ -36,9 +39,11 @@ dependencies:
36
39
  name: racc
37
40
  prerelease: false
38
41
  requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
39
43
  requirements:
40
44
  - - ">="
41
45
  - !ruby/object:Gem::Version
46
+ hash: 3
42
47
  segments:
43
48
  - 0
44
49
  version: "0"
@@ -48,9 +53,11 @@ dependencies:
48
53
  name: rexical
49
54
  prerelease: false
50
55
  requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
51
57
  requirements:
52
58
  - - ">="
53
59
  - !ruby/object:Gem::Version
60
+ hash: 3
54
61
  segments:
55
62
  - 0
56
63
  version: "0"
@@ -60,9 +67,11 @@ dependencies:
60
67
  name: rake-compiler
61
68
  prerelease: false
62
69
  requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
63
71
  requirements:
64
72
  - - ">="
65
73
  - !ruby/object:Gem::Version
74
+ hash: 3
66
75
  segments:
67
76
  - 0
68
77
  version: "0"
@@ -72,9 +81,11 @@ dependencies:
72
81
  name: minitest
73
82
  prerelease: false
74
83
  requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
75
85
  requirements:
76
86
  - - ">="
77
87
  - !ruby/object:Gem::Version
88
+ hash: 15
78
89
  segments:
79
90
  - 1
80
91
  - 6
@@ -86,9 +97,11 @@ dependencies:
86
97
  name: hoe
87
98
  prerelease: false
88
99
  requirement: &id006 !ruby/object:Gem::Requirement
100
+ none: false
89
101
  requirements:
90
102
  - - ">="
91
103
  - !ruby/object:Gem::Version
104
+ hash: 23
92
105
  segments:
93
106
  - 2
94
107
  - 6
@@ -100,9 +113,11 @@ dependencies:
100
113
  name: weakling
101
114
  prerelease: false
102
115
  requirement: &id007 !ruby/object:Gem::Requirement
116
+ none: false
103
117
  requirements:
104
118
  - - ">="
105
119
  - !ruby/object:Gem::Version
120
+ hash: 25
106
121
  segments:
107
122
  - 0
108
123
  - 0
@@ -145,6 +160,7 @@ extra_rdoc_files:
145
160
  - ext/nokogiri/xml_entity_decl.c
146
161
  - ext/nokogiri/xml_entity_reference.c
147
162
  - ext/nokogiri/xml_io.c
163
+ - ext/nokogiri/xml_libxml2_hacks.c
148
164
  - ext/nokogiri/xml_namespace.c
149
165
  - ext/nokogiri/xml_node.c
150
166
  - ext/nokogiri/xml_node_set.c
@@ -206,6 +222,8 @@ files:
206
222
  - ext/nokogiri/xml_entity_reference.h
207
223
  - ext/nokogiri/xml_io.c
208
224
  - ext/nokogiri/xml_io.h
225
+ - ext/nokogiri/xml_libxml2_hacks.c
226
+ - ext/nokogiri/xml_libxml2_hacks.h
209
227
  - ext/nokogiri/xml_namespace.c
210
228
  - ext/nokogiri/xml_namespace.h
211
229
  - ext/nokogiri/xml_node.c
@@ -319,7 +337,6 @@ files:
319
337
  - lib/nokogiri/html/sax/parser_context.rb
320
338
  - lib/nokogiri/syntax_error.rb
321
339
  - lib/nokogiri/version.rb
322
- - lib/nokogiri/version_warning.rb
323
340
  - lib/nokogiri/xml.rb
324
341
  - lib/nokogiri/xml/attr.rb
325
342
  - lib/nokogiri/xml/attribute_decl.rb
@@ -436,7 +453,6 @@ files:
436
453
  - test/xml/test_text.rb
437
454
  - test/xml/test_unparented_node.rb
438
455
  - test/xml/test_xpath.rb
439
- - lib/nokogiri/nokogiri.rb
440
456
  - ext/nokogiri/libcharset-1.dll
441
457
  - ext/nokogiri/libexslt.dll
442
458
  - ext/nokogiri/libiconv-2.dll
@@ -454,23 +470,27 @@ rdoc_options:
454
470
  require_paths:
455
471
  - lib
456
472
  required_ruby_version: !ruby/object:Gem::Requirement
473
+ none: false
457
474
  requirements:
458
475
  - - ">="
459
476
  - !ruby/object:Gem::Version
477
+ hash: 3
460
478
  segments:
461
479
  - 0
462
480
  version: "0"
463
481
  required_rubygems_version: !ruby/object:Gem::Requirement
482
+ none: false
464
483
  requirements:
465
484
  - - ">="
466
485
  - !ruby/object:Gem::Version
486
+ hash: 3
467
487
  segments:
468
488
  - 0
469
489
  version: "0"
470
490
  requirements: []
471
491
 
472
492
  rubyforge_project: nokogiri
473
- rubygems_version: 1.3.6
493
+ rubygems_version: 1.3.7
474
494
  signing_key:
475
495
  specification_version: 3
476
496
  summary: "Nokogiri (\xE9\x8B\xB8) is an HTML, XML, SAX, and Reader parser"
@@ -1 +0,0 @@
1
- require "nokogiri/#{RUBY_VERSION.sub(/\.\d+$/, '')}/nokogiri"
@@ -1,14 +0,0 @@
1
- module Nokogiri
2
- if self.is_2_6_16?
3
- VERSION_INFO['warnings'] << "libxml 2.6.16 is old and buggy."
4
- if !defined?(I_KNOW_I_AM_USING_AN_OLD_AND_BUGGY_VERSION_OF_LIBXML2)
5
- warn <<-eom
6
- HI. You're using libxml2 version 2.6.16 which is over 4 years old and has
7
- plenty of bugs. We suggest that for maximum HTML/XML parsing pleasure, you
8
- upgrade your version of libxml2 and re-install nokogiri. If you like using
9
- libxml2 version 2.6.16, but don't like this warning, please define the constant
10
- I_KNOW_I_AM_USING_AN_OLD_AND_BUGGY_VERSION_OF_LIBXML2 before requring nokogiri.
11
- eom
12
- end
13
- end
14
- end