nokogiri 1.6.8.rc1-java → 1.6.8.rc2-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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/.cross_rubies +2 -0
  3. data/CHANGELOG.rdoc +16 -2
  4. data/Gemfile +2 -2
  5. data/LICENSE.txt +1 -1
  6. data/Manifest.txt +0 -1
  7. data/Rakefile +5 -3
  8. data/ext/java/nokogiri/HtmlElementDescription.java +5 -2
  9. data/ext/java/nokogiri/NokogiriService.java +19 -0
  10. data/ext/java/nokogiri/XmlNode.java +7 -0
  11. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +8 -1
  12. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +1 -2
  13. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +1 -1
  14. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +0 -1
  15. data/ext/java/nokogiri/internals/ParserContext.java +4 -0
  16. data/ext/java/nokogiri/internals/SaveContextVisitor.java +13 -12
  17. data/ext/nokogiri/extconf.rb +1 -2
  18. data/ext/nokogiri/html_document.c +6 -6
  19. data/ext/nokogiri/html_element_description.c +1 -1
  20. data/ext/nokogiri/html_entity_lookup.c +1 -1
  21. data/ext/nokogiri/html_sax_parser_context.c +4 -4
  22. data/ext/nokogiri/html_sax_push_parser.c +2 -2
  23. data/ext/nokogiri/xml_attr.c +2 -2
  24. data/ext/nokogiri/xml_comment.c +1 -1
  25. data/ext/nokogiri/xml_document.c +18 -18
  26. data/ext/nokogiri/xml_encoding_handler.c +3 -3
  27. data/ext/nokogiri/xml_entity_reference.c +1 -1
  28. data/ext/nokogiri/xml_node.c +27 -27
  29. data/ext/nokogiri/xml_node_set.c +3 -11
  30. data/ext/nokogiri/xml_processing_instruction.c +2 -2
  31. data/ext/nokogiri/xml_reader.c +6 -6
  32. data/ext/nokogiri/xml_sax_parser_context.c +1 -1
  33. data/ext/nokogiri/xml_sax_push_parser.c +1 -1
  34. data/ext/nokogiri/xml_schema.c +1 -1
  35. data/ext/nokogiri/xml_text.c +1 -1
  36. data/ext/nokogiri/xml_xpath_context.c +6 -6
  37. data/ext/nokogiri/xslt_stylesheet.c +6 -6
  38. data/lib/nekohtml.jar +0 -0
  39. data/lib/nokogiri/nokogiri.jar +0 -0
  40. data/lib/nokogiri/version.rb +1 -1
  41. data/lib/nokogiri/xml/node.rb +5 -9
  42. data/lib/nokogiri/xml/node_set.rb +3 -3
  43. data/test/html/test_document.rb +3 -3
  44. data/test/html/test_document_encoding.rb +4 -4
  45. data/test/html/test_node_encoding.rb +60 -0
  46. data/test/test_css_cache.rb +1 -1
  47. data/test/test_reader.rb +19 -19
  48. data/test/xml/sax/test_parser.rb +3 -7
  49. data/test/xml/test_document_encoding.rb +3 -3
  50. data/test/xml/test_namespace.rb +2 -2
  51. data/test/xml/test_node.rb +4 -4
  52. data/test/xml/test_node_encoding.rb +33 -69
  53. data/test/xml/test_node_set.rb +1 -1
  54. data/test/xml/test_unparented_node.rb +1 -1
  55. data/test_all +15 -9
  56. metadata +4 -6
  57. data/CHANGELOG.ja.rdoc +0 -1075
@@ -22,7 +22,7 @@ static void dealloc(nokogiriXsltStylesheetTuple *wrapper)
22
22
  NOKOGIRI_DEBUG_START(doc);
23
23
  xsltFreeStylesheet(doc); /* commented out for now. */
24
24
  NOKOGIRI_DEBUG_END(doc);
25
-
25
+
26
26
  free(wrapper);
27
27
  }
28
28
 
@@ -47,7 +47,7 @@ VALUE Nokogiri_wrap_xslt_stylesheet(xsltStylesheetPtr ss)
47
47
 
48
48
  self = Data_Make_Struct(cNokogiriXsltStylesheet, nokogiriXsltStylesheetTuple,
49
49
  mark, dealloc, wrapper);
50
-
50
+
51
51
  ss->_private = (void *)self;
52
52
  wrapper->ss = ss;
53
53
  wrapper->func_instances = rb_ary_new();
@@ -122,7 +122,7 @@ static void swallow_superfluous_xml_errors(void * userdata, xmlErrorPtr error, .
122
122
  * returns Nokogiri::XML::Document
123
123
  *
124
124
  * Example:
125
- *
125
+ *
126
126
  * doc = Nokogiri::XML(File.read(ARGV[0]))
127
127
  * xslt = Nokogiri::XSLT(File.read(ARGV[1]))
128
128
  * puts xslt.transform(doc, ['key', 'value'])
@@ -158,7 +158,7 @@ static VALUE transform(int argc, VALUE* argv, VALUE self)
158
158
  params = calloc((size_t)param_len+1, sizeof(char*));
159
159
  for (j = 0 ; j < param_len ; j++) {
160
160
  VALUE entry = rb_ary_entry(paramobj, j);
161
- const char * ptr = StringValuePtr(entry);
161
+ const char * ptr = StringValueCStr(entry);
162
162
  params[j] = ptr;
163
163
  }
164
164
  params[param_len] = 0 ;
@@ -211,7 +211,7 @@ static void * initFunc(xsltTransformContextPtr ctxt, const xmlChar *uri)
211
211
  for(i = 0; i < RARRAY_LEN(methods); i++) {
212
212
  VALUE method_name = rb_obj_as_string(rb_ary_entry(methods, i));
213
213
  xsltRegisterExtFunction(ctxt,
214
- (unsigned char *)StringValuePtr(method_name), uri, method_caller);
214
+ (unsigned char *)StringValueCStr(method_name), uri, method_caller);
215
215
  }
216
216
 
217
217
  Data_Get_Struct(ctxt->style->_private, nokogiriXsltStylesheetTuple,
@@ -245,7 +245,7 @@ static VALUE registr(VALUE self, VALUE uri, VALUE obj)
245
245
  if(NIL_P(modules)) rb_raise(rb_eRuntimeError, "wtf! @modules isn't set");
246
246
 
247
247
  rb_hash_aset(modules, uri, obj);
248
- xsltRegisterExtModule((unsigned char *)StringValuePtr(uri), initFunc, shutdownFunc);
248
+ xsltRegisterExtModule((unsigned char *)StringValueCStr(uri), initFunc, shutdownFunc);
249
249
  return self;
250
250
  }
251
251
 
data/lib/nekohtml.jar CHANGED
Binary file
Binary file
@@ -1,6 +1,6 @@
1
1
  module Nokogiri
2
2
  # The version of Nokogiri you are using
3
- VERSION = '1.6.8.rc1'
3
+ VERSION = '1.6.8.rc2'
4
4
 
5
5
  class VersionInfo # :nodoc:
6
6
  def jruby?
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'stringio'
2
3
  require 'nokogiri/xml/node/save_options'
3
4
 
@@ -331,13 +332,13 @@ module Nokogiri
331
332
  ###
332
333
  # Get the attribute values for this Node.
333
334
  def values
334
- attribute_nodes.map { |node| node.value }
335
+ attribute_nodes.map(&:value)
335
336
  end
336
337
 
337
338
  ###
338
339
  # Get the attribute names for this Node.
339
340
  def keys
340
- attribute_nodes.map { |node| node.node_name }
341
+ attribute_nodes.map(&:node_name)
341
342
  end
342
343
 
343
344
  ###
@@ -439,12 +440,6 @@ module Nokogiri
439
440
  def namespaces
440
441
  Hash[namespace_scopes.map { |nd|
441
442
  key = ['xmlns', nd.prefix].compact.join(':')
442
- if document.encoding
443
- begin
444
- key.force_encoding document.encoding
445
- rescue ArgumentError
446
- end
447
- end
448
443
  [key, nd.href]
449
444
  }]
450
445
  end
@@ -546,9 +541,10 @@ module Nokogiri
546
541
  return NodeSet.new(document, parents) unless selector
547
542
 
548
543
  root = parents.last
544
+ search_results = root.search(selector)
549
545
 
550
546
  NodeSet.new(document, parents.find_all { |parent|
551
- root.search(selector).include?(parent)
547
+ search_results.include?(parent)
552
548
  })
553
549
  end
554
550
 
@@ -191,7 +191,7 @@ module Nokogiri
191
191
  ###
192
192
  # Get the inner text of all contained Node objects
193
193
  def inner_text
194
- collect{|j| j.inner_text}.join('')
194
+ collect(&:inner_text).join('')
195
195
  end
196
196
  alias :text :inner_text
197
197
 
@@ -215,7 +215,7 @@ module Nokogiri
215
215
  ###
216
216
  # Convert this NodeSet to a string.
217
217
  def to_s
218
- map { |x| x.to_s }.join
218
+ map(&:to_s).join
219
219
  end
220
220
 
221
221
  ###
@@ -296,7 +296,7 @@ module Nokogiri
296
296
  ###
297
297
  # Return a nicely formated string representation
298
298
  def inspect
299
- "[#{map { |c| c.inspect }.join ', '}]"
299
+ "[#{map(&:inspect).join ', '}]"
300
300
  end
301
301
 
302
302
  alias :+ :|
@@ -97,7 +97,7 @@ module Nokogiri
97
97
  rescue Exception => e
98
98
  skip("This test needs the internet. Skips if no internet available. (#{e})")
99
99
  end
100
- doc = Nokogiri::HTML html ,"http:/foobar.foobar/"
100
+ doc = Nokogiri::HTML html ,"http:/foobar.foobar/", 'UTF-8'
101
101
  refute_empty doc.to_s, "Document should not be empty"
102
102
  end
103
103
 
@@ -422,7 +422,7 @@ eohtml
422
422
  eohtml
423
423
  set = html.css('p, a')
424
424
  assert_equal(2, set.length)
425
- assert_equal ['a tag', 'p tag'].sort, set.map { |x| x.content }.sort
425
+ assert_equal ['a tag', 'p tag'].sort, set.map(&:content).sort
426
426
  end
427
427
 
428
428
  def test_inner_text
@@ -600,7 +600,7 @@ eohtml
600
600
  eohtml
601
601
  list = doc.css('.red')
602
602
  assert_equal 2, list.length
603
- assert_equal %w{ RED RED }, list.map { |x| x.text }
603
+ assert_equal %w{ RED RED }, list.map(&:text)
604
604
  end
605
605
 
606
606
  def test_parse_can_take_io
@@ -107,16 +107,16 @@ module Nokogiri
107
107
  def test_document_xhtml_enc
108
108
  [ENCODING_XHTML_FILE, ENCODING_HTML_FILE].each { |file|
109
109
  doc_from_string_enc = Nokogiri::HTML(binread(file), nil, 'Shift_JIS')
110
- ary_from_string_enc = doc_from_string_enc.xpath('//p/text()').map { |text| text.text }
110
+ ary_from_string_enc = doc_from_string_enc.xpath('//p/text()').map(&:text)
111
111
 
112
112
  doc_from_string = Nokogiri::HTML(binread(file))
113
- ary_from_string = doc_from_string.xpath('//p/text()').map { |text| text.text }
113
+ ary_from_string = doc_from_string.xpath('//p/text()').map(&:text)
114
114
 
115
115
  doc_from_file_enc = Nokogiri::HTML(binopen(file), nil, 'Shift_JIS')
116
- ary_from_file_enc = doc_from_file_enc.xpath('//p/text()').map { |text| text.text }
116
+ ary_from_file_enc = doc_from_file_enc.xpath('//p/text()').map(&:text)
117
117
 
118
118
  doc_from_file = Nokogiri::HTML(binopen(file))
119
- ary_from_file = doc_from_file.xpath('//p/text()').map { |text| text.text }
119
+ ary_from_file = doc_from_file.xpath('//p/text()').map(&:text)
120
120
 
121
121
  title = 'たこ焼き仮面'
122
122
 
@@ -4,6 +4,48 @@ require "helper"
4
4
  module Nokogiri
5
5
  module HTML
6
6
  class TestNodeEncoding < Nokogiri::TestCase
7
+ def setup
8
+ super
9
+ @html = Nokogiri::HTML(File.open(NICH_FILE, "rb"))
10
+ end
11
+
12
+ def test_get_attribute
13
+ node = @html.css('a').first
14
+ assert_equal 'UTF-8', node['href'].encoding.name
15
+ end
16
+
17
+ def test_text_encoding_is_utf_8
18
+ assert_equal 'UTF-8', @html.text.encoding.name
19
+ end
20
+
21
+ def test_serialize_encoding_html
22
+ assert_equal @html.encoding.downcase,
23
+ @html.serialize.encoding.name.downcase
24
+
25
+ @doc = Nokogiri::HTML(@html.serialize)
26
+ assert_equal @html.serialize, @doc.serialize
27
+ end
28
+
29
+ def test_encode_special_chars
30
+ foo = @html.css('a').first.encode_special_chars('foo')
31
+ assert_equal 'UTF-8', foo.encoding.name
32
+ end
33
+
34
+ def test_content
35
+ node = @html.css('a').first
36
+ assert_equal 'UTF-8', node.content.encoding.name
37
+ end
38
+
39
+ def test_name
40
+ node = @html.css('a').first
41
+ assert_equal 'UTF-8', node.name.encoding.name
42
+ end
43
+
44
+ def test_path
45
+ node = @html.css('a').first
46
+ assert_equal 'UTF-8', node.path.encoding.name
47
+ end
48
+
7
49
  def test_inner_html
8
50
  doc = Nokogiri::HTML File.open(SHIFT_JIS_HTML, 'rb')
9
51
 
@@ -20,6 +62,24 @@ module Nokogiri
20
62
  contents = doc.at('h2').inner_html
21
63
  assert_match hello, contents
22
64
  end
65
+
66
+ def test_encoding_GH_1113
67
+ doc = Nokogiri::HTML::Document.new
68
+ hex = '<p>&#x1f340;</p>'
69
+ decimal = '<p>&#127808;</p>'
70
+ encoded = '<p>🍀</p>'
71
+
72
+ doc.encoding = 'UTF-8'
73
+ [hex, decimal, encoded].each do |document|
74
+ assert_equal encoded, doc.fragment(document).to_s
75
+ end
76
+
77
+ doc.encoding = 'US-ASCII'
78
+ expected = Nokogiri.jruby? ? hex : decimal
79
+ [hex, decimal].each do |document|
80
+ assert_equal expected, doc.fragment(document).to_s
81
+ end
82
+ end
23
83
  end
24
84
  end
25
85
  end
@@ -6,7 +6,7 @@ class TestCssCache < Nokogiri::TestCase
6
6
  super
7
7
  @css = "a1 > b2 > c3"
8
8
  @parse_result = Nokogiri::CSS.parse(@css)
9
- @to_xpath_result = @parse_result.map {|ast| ast.to_xpath}
9
+ @to_xpath_result = @parse_result.map(&:to_xpath)
10
10
  Nokogiri::CSS::Parser.class_eval do
11
11
  class << @cache
12
12
  alias :old_bracket :[]
data/test/test_reader.rb CHANGED
@@ -85,7 +85,7 @@ class TestReader < Nokogiri::TestCase
85
85
  reader = Nokogiri::XML::Reader.from_io(io)
86
86
  assert_equal false, reader.default?
87
87
  assert_equal [false, false, false, false, false, false, false],
88
- reader.map { |x| x.default? }
88
+ reader.map(&:default?)
89
89
  end
90
90
 
91
91
  def test_io
@@ -93,7 +93,7 @@ class TestReader < Nokogiri::TestCase
93
93
  reader = Nokogiri::XML::Reader(io)
94
94
  assert_equal false, reader.default?
95
95
  assert_equal [false, false, false, false, false, false, false],
96
- reader.map { |x| x.default? }
96
+ reader.map(&:default?)
97
97
  end
98
98
 
99
99
  def test_string_io
@@ -105,7 +105,7 @@ class TestReader < Nokogiri::TestCase
105
105
  reader = Nokogiri::XML::Reader(io)
106
106
  assert_equal false, reader.default?
107
107
  assert_equal [false, false, false, false, false, false, false],
108
- reader.map { |x| x.default? }
108
+ reader.map(&:default?)
109
109
  end
110
110
 
111
111
  class ReallyBadIO
@@ -156,7 +156,7 @@ class TestReader < Nokogiri::TestCase
156
156
  eoxml
157
157
  assert_equal false, reader.default?
158
158
  assert_equal [false, false, false, false, false, false, false],
159
- reader.map { |x| x.default? }
159
+ reader.map(&:default?)
160
160
  end
161
161
 
162
162
  def test_value?
@@ -167,7 +167,7 @@ class TestReader < Nokogiri::TestCase
167
167
  eoxml
168
168
  assert_equal false, reader.value?
169
169
  assert_equal [false, true, false, true, false, true, false],
170
- reader.map { |x| x.value? }
170
+ reader.map(&:value?)
171
171
  end
172
172
 
173
173
  def test_read_error_document
@@ -191,7 +191,7 @@ class TestReader < Nokogiri::TestCase
191
191
  eoxml
192
192
  assert_equal false, reader.attributes?
193
193
  assert_equal [true, false, true, false, true, false, true],
194
- reader.map { |x| x.attributes? }
194
+ reader.map(&:attributes?)
195
195
  end
196
196
 
197
197
  def test_attributes
@@ -208,7 +208,7 @@ class TestReader < Nokogiri::TestCase
208
208
  {}, {"awesome"=>"true"}, {}, {"awesome"=>"true"}, {},
209
209
  {'xmlns:tenderlove'=>'http://tenderlovemaking.com/',
210
210
  'xmlns'=>'http://mothership.connection.com/'}],
211
- reader.map { |x| x.attributes }
211
+ reader.map(&:attributes)
212
212
  end
213
213
 
214
214
  def test_attribute_roundtrip
@@ -257,7 +257,7 @@ class TestReader < Nokogiri::TestCase
257
257
  </x>
258
258
  eoxml
259
259
  assert_equal 0, reader.attribute_count
260
- assert_equal [1, 0, 1, 0, 0, 0, 0], reader.map { |x| x.attribute_count }
260
+ assert_equal [1, 0, 1, 0, 0, 0, 0], reader.map(&:attribute_count)
261
261
  end
262
262
 
263
263
  def test_depth
@@ -267,7 +267,7 @@ class TestReader < Nokogiri::TestCase
267
267
  </x>
268
268
  eoxml
269
269
  assert_equal 0, reader.depth
270
- assert_equal [0, 1, 1, 2, 1, 1, 0], reader.map { |x| x.depth }
270
+ assert_equal [0, 1, 1, 2, 1, 1, 0], reader.map(&:depth)
271
271
  end
272
272
 
273
273
  def test_encoding
@@ -278,7 +278,7 @@ class TestReader < Nokogiri::TestCase
278
278
  </awesome>
279
279
  eoxml
280
280
  reader = Nokogiri::XML::Reader.from_memory(string, nil, 'UTF-8')
281
- assert_equal ['UTF-8'], reader.map { |x| x.encoding }.uniq
281
+ assert_equal ['UTF-8'], reader.map(&:encoding).uniq
282
282
  end
283
283
 
284
284
  def test_xml_version
@@ -288,7 +288,7 @@ class TestReader < Nokogiri::TestCase
288
288
  </x>
289
289
  eoxml
290
290
  assert_nil reader.xml_version
291
- assert_equal ['1.0'], reader.map { |x| x.xml_version }.uniq
291
+ assert_equal ['1.0'], reader.map(&:xml_version).uniq
292
292
  end
293
293
 
294
294
  def test_lang
@@ -300,7 +300,7 @@ class TestReader < Nokogiri::TestCase
300
300
  eoxml
301
301
  assert_nil reader.lang
302
302
  assert_equal [nil, nil, "en", "en", "en", nil, "ja", "ja", "ja", nil, nil],
303
- reader.map { |x| x.lang }
303
+ reader.map(&:lang)
304
304
  end
305
305
 
306
306
  def test_value
@@ -311,7 +311,7 @@ class TestReader < Nokogiri::TestCase
311
311
  eoxml
312
312
  assert_nil reader.value
313
313
  assert_equal [nil, "\n ", nil, "snuggles!", nil, "\n ", nil],
314
- reader.map { |x| x.value }
314
+ reader.map(&:value)
315
315
  end
316
316
 
317
317
  def test_prefix
@@ -322,7 +322,7 @@ class TestReader < Nokogiri::TestCase
322
322
  eoxml
323
323
  assert_nil reader.prefix
324
324
  assert_equal [nil, nil, "edi", nil, "edi", nil, nil],
325
- reader.map { |n| n.prefix }
325
+ reader.map(&:prefix)
326
326
  end
327
327
 
328
328
  def test_node_type
@@ -332,7 +332,7 @@ class TestReader < Nokogiri::TestCase
332
332
  </x>
333
333
  eoxml
334
334
  assert_equal 0, reader.node_type
335
- assert_equal [1, 14, 1, 3, 15, 14, 15], reader.map { |n| n.node_type }
335
+ assert_equal [1, 14, 1, 3, 15, 14, 15], reader.map(&:node_type)
336
336
  end
337
337
 
338
338
  def test_inner_xml
@@ -383,7 +383,7 @@ class TestReader < Nokogiri::TestCase
383
383
  "http://ecommerce.example.org/schema",
384
384
  nil,
385
385
  nil],
386
- reader.map { |n| n.namespace_uri })
386
+ reader.map(&:namespace_uri))
387
387
  end
388
388
 
389
389
  def test_namespaced_attributes
@@ -413,7 +413,7 @@ class TestReader < Nokogiri::TestCase
413
413
  eoxml
414
414
  assert_nil reader.local_name
415
415
  assert_equal(["x", "#text", "foo", "#text", "foo", "#text", "x"],
416
- reader.map { |n| n.local_name })
416
+ reader.map(&:local_name))
417
417
  end
418
418
 
419
419
  def test_name
@@ -424,7 +424,7 @@ class TestReader < Nokogiri::TestCase
424
424
  eoxml
425
425
  assert_nil reader.name
426
426
  assert_equal(["x", "#text", "edi:foo", "#text", "edi:foo", "#text", "x"],
427
- reader.map { |n| n.name })
427
+ reader.map(&:name))
428
428
  end
429
429
 
430
430
  def test_base_uri
@@ -452,7 +452,7 @@ class TestReader < Nokogiri::TestCase
452
452
  "http://base.example.org/base/relative",
453
453
  "http://base.example.org/base/",
454
454
  "http://base.example.org/base/"],
455
- reader.map {|n| n.base_uri })
455
+ reader.map(&:base_uri))
456
456
  end
457
457
 
458
458
  def test_xlink_href_without_base_uri
@@ -136,12 +136,8 @@ module Nokogiri
136
136
  </root>
137
137
  eoxml
138
138
  assert_equal 5, @parser.document.start_elements.length
139
- assert @parser.document.start_elements.map { |se|
140
- se.first
141
- }.include?('foo:bar')
142
- assert @parser.document.end_elements.map { |se|
143
- se.first
144
- }.include?('foo:bar')
139
+ assert @parser.document.start_elements.map(&:first).include?('foo:bar')
140
+ assert @parser.document.end_elements.map(&:first).include?('foo:bar')
145
141
  end
146
142
 
147
143
  def test_start_is_called_without_namespace
@@ -151,7 +147,7 @@ module Nokogiri
151
147
  </root>
152
148
  eoxml
153
149
  assert_equal ['root', 'foo:f', 'bar'],
154
- @parser.document.start_elements.map { |x| x.first }
150
+ @parser.document.start_elements.map(&:first)
155
151
  end
156
152
 
157
153
  def test_parser_sets_encoding