nokogiri 1.4.2 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (54) 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/test/css/test_parser.rb +11 -1
  36. data/test/html/sax/test_parser_context.rb +2 -2
  37. data/test/html/test_document.rb +2 -2
  38. data/test/html/test_document_fragment.rb +34 -6
  39. data/test/test_memory_leak.rb +2 -2
  40. data/test/test_reader.rb +28 -6
  41. data/test/test_xslt_transforms.rb +29 -28
  42. data/test/xml/test_attr.rb +31 -4
  43. data/test/xml/test_builder.rb +5 -5
  44. data/test/xml/test_cdata.rb +3 -3
  45. data/test/xml/test_document.rb +8 -8
  46. data/test/xml/test_document_fragment.rb +2 -2
  47. data/test/xml/test_node.rb +1 -1
  48. data/test/xml/test_node_reparenting.rb +26 -11
  49. data/test/xml/test_node_set.rb +38 -2
  50. data/test/xml/test_text.rb +11 -2
  51. data/test/xml/test_unparented_node.rb +1 -1
  52. data/test/xml/test_xpath.rb +78 -11
  53. metadata +24 -5
  54. data/lib/nokogiri/version_warning.rb +0 -14
@@ -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: ruby
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:
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
@@ -131,6 +144,7 @@ extra_rdoc_files:
131
144
  - ext/nokogiri/xml_entity_decl.c
132
145
  - ext/nokogiri/xml_entity_reference.c
133
146
  - ext/nokogiri/xml_io.c
147
+ - ext/nokogiri/xml_libxml2_hacks.c
134
148
  - ext/nokogiri/xml_namespace.c
135
149
  - ext/nokogiri/xml_node.c
136
150
  - ext/nokogiri/xml_node_set.c
@@ -192,6 +206,8 @@ files:
192
206
  - ext/nokogiri/xml_entity_reference.h
193
207
  - ext/nokogiri/xml_io.c
194
208
  - ext/nokogiri/xml_io.h
209
+ - ext/nokogiri/xml_libxml2_hacks.c
210
+ - ext/nokogiri/xml_libxml2_hacks.h
195
211
  - ext/nokogiri/xml_namespace.c
196
212
  - ext/nokogiri/xml_namespace.h
197
213
  - ext/nokogiri/xml_node.c
@@ -305,7 +321,6 @@ files:
305
321
  - lib/nokogiri/html/sax/parser_context.rb
306
322
  - lib/nokogiri/syntax_error.rb
307
323
  - lib/nokogiri/version.rb
308
- - lib/nokogiri/version_warning.rb
309
324
  - lib/nokogiri/xml.rb
310
325
  - lib/nokogiri/xml/attr.rb
311
326
  - lib/nokogiri/xml/attribute_decl.rb
@@ -433,23 +448,27 @@ rdoc_options:
433
448
  require_paths:
434
449
  - lib
435
450
  required_ruby_version: !ruby/object:Gem::Requirement
451
+ none: false
436
452
  requirements:
437
453
  - - ">="
438
454
  - !ruby/object:Gem::Version
455
+ hash: 3
439
456
  segments:
440
457
  - 0
441
458
  version: "0"
442
459
  required_rubygems_version: !ruby/object:Gem::Requirement
460
+ none: false
443
461
  requirements:
444
462
  - - ">="
445
463
  - !ruby/object:Gem::Version
464
+ hash: 3
446
465
  segments:
447
466
  - 0
448
467
  version: "0"
449
468
  requirements: []
450
469
 
451
470
  rubyforge_project: nokogiri
452
- rubygems_version: 1.3.6
471
+ rubygems_version: 1.3.7
453
472
  signing_key:
454
473
  specification_version: 3
455
474
  summary: "Nokogiri (\xE9\x8B\xB8) is an HTML, XML, SAX, and Reader parser"
@@ -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