nokogiri 1.4.7-x86-mingw32 → 1.5.0-x86-mingw32

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 (132) hide show
  1. data/CHANGELOG.ja.rdoc +59 -1
  2. data/CHANGELOG.rdoc +51 -2
  3. data/Manifest.txt +66 -66
  4. data/README.ja.rdoc +4 -0
  5. data/README.rdoc +31 -3
  6. data/Rakefile +111 -135
  7. data/bin/nokogiri +1 -2
  8. data/ext/nokogiri/extconf.rb +9 -3
  9. data/ext/nokogiri/nokogiri.c +21 -3
  10. data/ext/nokogiri/nokogiri.h +0 -2
  11. data/ext/nokogiri/xml_node.c +0 -6
  12. data/ext/nokogiri/xml_relax_ng.c +0 -7
  13. data/ext/nokogiri/xml_sax_parser.c +9 -4
  14. data/ext/nokogiri/xslt_stylesheet.c +5 -1
  15. data/lib/nokogiri.rb +19 -25
  16. data/lib/nokogiri/1.8/nokogiri.so +0 -0
  17. data/lib/nokogiri/1.9/nokogiri.so +0 -0
  18. data/lib/nokogiri/css.rb +0 -1
  19. data/lib/nokogiri/html.rb +1 -0
  20. data/lib/nokogiri/html/document.rb +9 -2
  21. data/lib/nokogiri/html/element_description_defaults.rb +671 -0
  22. data/lib/nokogiri/version.rb +76 -31
  23. data/lib/nokogiri/xml/attribute_decl.rb +1 -1
  24. data/lib/nokogiri/xml/builder.rb +7 -0
  25. data/lib/nokogiri/xml/document.rb +17 -1
  26. data/lib/nokogiri/xml/document_fragment.rb +14 -0
  27. data/lib/nokogiri/xml/dtd.rb +1 -1
  28. data/lib/nokogiri/xml/element_decl.rb +1 -1
  29. data/lib/nokogiri/xml/entity_decl.rb +1 -1
  30. data/lib/nokogiri/xml/node.rb +39 -15
  31. data/lib/nokogiri/xml/node/save_options.rb +14 -5
  32. data/lib/nokogiri/xml/node_set.rb +7 -0
  33. data/lib/nokogiri/xml/reader.rb +2 -2
  34. data/lib/nokogiri/xml/sax/document.rb +2 -2
  35. data/lib/nokogiri/xslt/stylesheet.rb +1 -1
  36. data/nokogiri_help_responses.md +40 -0
  37. data/tasks/cross_compile.rb +134 -155
  38. data/tasks/nokogiri.org.rb +18 -0
  39. data/tasks/test.rb +2 -2
  40. data/test/files/metacharset.html +10 -0
  41. data/test/files/noencoding.html +47 -0
  42. data/test/helper.rb +2 -1
  43. data/test/html/sax/test_parser.rb +22 -5
  44. data/test/html/test_document.rb +21 -2
  45. data/test/html/test_document_encoding.rb +9 -1
  46. data/test/html/test_document_fragment.rb +5 -3
  47. data/test/html/test_element_description.rb +4 -2
  48. data/test/test_memory_leak.rb +4 -39
  49. data/test/test_nokogiri.rb +14 -20
  50. data/test/test_reader.rb +12 -8
  51. data/test/xml/node/test_save_options.rb +10 -2
  52. data/test/xml/sax/test_parser.rb +14 -7
  53. data/test/xml/test_attribute_decl.rb +7 -3
  54. data/test/xml/test_builder.rb +17 -0
  55. data/test/xml/test_document.rb +31 -4
  56. data/test/xml/test_dtd.rb +13 -3
  57. data/test/xml/test_element_content.rb +1 -1
  58. data/test/xml/test_element_decl.rb +1 -1
  59. data/test/xml/test_entity_decl.rb +12 -10
  60. data/test/xml/test_namespace.rb +7 -5
  61. data/test/xml/test_node.rb +21 -10
  62. data/test/xml/test_node_reparenting.rb +16 -3
  63. data/test/xml/test_node_set.rb +34 -0
  64. data/test/xslt/test_custom_functions.rb +2 -2
  65. data/test/xslt/test_exception_handling.rb +37 -0
  66. metadata +110 -88
  67. data/lib/nokogiri/ffi/encoding_handler.rb +0 -42
  68. data/lib/nokogiri/ffi/html/document.rb +0 -28
  69. data/lib/nokogiri/ffi/html/element_description.rb +0 -81
  70. data/lib/nokogiri/ffi/html/entity_lookup.rb +0 -16
  71. data/lib/nokogiri/ffi/html/sax/parser_context.rb +0 -38
  72. data/lib/nokogiri/ffi/io_callbacks.rb +0 -42
  73. data/lib/nokogiri/ffi/libxml.rb +0 -420
  74. data/lib/nokogiri/ffi/structs/common_node.rb +0 -38
  75. data/lib/nokogiri/ffi/structs/html_elem_desc.rb +0 -24
  76. data/lib/nokogiri/ffi/structs/html_entity_desc.rb +0 -13
  77. data/lib/nokogiri/ffi/structs/xml_alloc.rb +0 -16
  78. data/lib/nokogiri/ffi/structs/xml_attr.rb +0 -20
  79. data/lib/nokogiri/ffi/structs/xml_attribute.rb +0 -27
  80. data/lib/nokogiri/ffi/structs/xml_buffer.rb +0 -16
  81. data/lib/nokogiri/ffi/structs/xml_char_encoding_handler.rb +0 -11
  82. data/lib/nokogiri/ffi/structs/xml_document.rb +0 -117
  83. data/lib/nokogiri/ffi/structs/xml_dtd.rb +0 -28
  84. data/lib/nokogiri/ffi/structs/xml_element.rb +0 -26
  85. data/lib/nokogiri/ffi/structs/xml_element_content.rb +0 -17
  86. data/lib/nokogiri/ffi/structs/xml_entity.rb +0 -32
  87. data/lib/nokogiri/ffi/structs/xml_enumeration.rb +0 -12
  88. data/lib/nokogiri/ffi/structs/xml_node.rb +0 -28
  89. data/lib/nokogiri/ffi/structs/xml_node_set.rb +0 -53
  90. data/lib/nokogiri/ffi/structs/xml_notation.rb +0 -11
  91. data/lib/nokogiri/ffi/structs/xml_ns.rb +0 -15
  92. data/lib/nokogiri/ffi/structs/xml_parser_context.rb +0 -20
  93. data/lib/nokogiri/ffi/structs/xml_parser_input.rb +0 -19
  94. data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +0 -14
  95. data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +0 -51
  96. data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +0 -124
  97. data/lib/nokogiri/ffi/structs/xml_schema.rb +0 -13
  98. data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +0 -31
  99. data/lib/nokogiri/ffi/structs/xml_text_reader.rb +0 -12
  100. data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +0 -38
  101. data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +0 -35
  102. data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +0 -20
  103. data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +0 -13
  104. data/lib/nokogiri/ffi/weak_bucket.rb +0 -40
  105. data/lib/nokogiri/ffi/xml/attr.rb +0 -41
  106. data/lib/nokogiri/ffi/xml/attribute_decl.rb +0 -27
  107. data/lib/nokogiri/ffi/xml/cdata.rb +0 -19
  108. data/lib/nokogiri/ffi/xml/comment.rb +0 -18
  109. data/lib/nokogiri/ffi/xml/document.rb +0 -174
  110. data/lib/nokogiri/ffi/xml/document_fragment.rb +0 -21
  111. data/lib/nokogiri/ffi/xml/dtd.rb +0 -67
  112. data/lib/nokogiri/ffi/xml/element_content.rb +0 -43
  113. data/lib/nokogiri/ffi/xml/element_decl.rb +0 -19
  114. data/lib/nokogiri/ffi/xml/entity_decl.rb +0 -36
  115. data/lib/nokogiri/ffi/xml/entity_reference.rb +0 -19
  116. data/lib/nokogiri/ffi/xml/namespace.rb +0 -44
  117. data/lib/nokogiri/ffi/xml/node.rb +0 -559
  118. data/lib/nokogiri/ffi/xml/node_set.rb +0 -150
  119. data/lib/nokogiri/ffi/xml/processing_instruction.rb +0 -20
  120. data/lib/nokogiri/ffi/xml/reader.rb +0 -236
  121. data/lib/nokogiri/ffi/xml/relax_ng.rb +0 -85
  122. data/lib/nokogiri/ffi/xml/sax/parser.rb +0 -143
  123. data/lib/nokogiri/ffi/xml/sax/parser_context.rb +0 -79
  124. data/lib/nokogiri/ffi/xml/sax/push_parser.rb +0 -51
  125. data/lib/nokogiri/ffi/xml/schema.rb +0 -109
  126. data/lib/nokogiri/ffi/xml/syntax_error.rb +0 -98
  127. data/lib/nokogiri/ffi/xml/text.rb +0 -18
  128. data/lib/nokogiri/ffi/xml/xpath.rb +0 -9
  129. data/lib/nokogiri/ffi/xml/xpath_context.rb +0 -153
  130. data/lib/nokogiri/ffi/xslt/stylesheet.rb +0 -77
  131. data/lib/nokogiri/version_warning.rb +0 -14
  132. data/test/ffi/test_document.rb +0 -35
@@ -1,43 +1,88 @@
1
1
  module Nokogiri
2
2
  # The version of Nokogiri you are using
3
- VERSION = '1.4.7'
3
+ VERSION = '1.5.0'
4
4
 
5
- # More complete version information about libxml
6
- VERSION_INFO = {}
7
- VERSION_INFO['warnings'] = []
8
- VERSION_INFO['nokogiri'] = Nokogiri::VERSION
9
- VERSION_INFO['ruby'] = {}
10
- VERSION_INFO['ruby']['version'] = ::RUBY_VERSION
11
- VERSION_INFO['ruby']['platform'] = ::RUBY_PLATFORM
12
- VERSION_INFO['ruby']['description'] = ::RUBY_DESCRIPTION if defined? ::RUBY_DESCRIPTION
13
- VERSION_INFO['ruby']['engine'] = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'mri'
14
- VERSION_INFO['ruby']['jruby'] = ::JRUBY_VERSION if RUBY_PLATFORM == "java"
15
- if defined?(LIBXML_VERSION)
16
- VERSION_INFO['libxml'] = {}
17
- VERSION_INFO['libxml']['binding'] = 'extension'
18
- VERSION_INFO['libxml']['compiled'] = LIBXML_VERSION
19
- VERSION_INFO['libxml']['loaded'] = LIBXML_PARSER_VERSION.scan(/^(.*)(..)(..)$/).first.collect{|j|j.to_i}.join(".")
20
-
21
- if VERSION_INFO['libxml']['compiled'] != VERSION_INFO['libxml']['loaded']
22
- warning = "Nokogiri was built against LibXML version #{VERSION_INFO['libxml']['compiled']}, but has dynamically loaded #{VERSION_INFO['libxml']['loaded']}"
23
- VERSION_INFO['warnings'] << warning
24
- warn "WARNING: #{warning}"
5
+ class VersionInfo # :nodoc:
6
+ def jruby?
7
+ ::JRUBY_VERSION if RUBY_PLATFORM == "java"
25
8
  end
26
- end
27
9
 
28
- def self.uses_libxml? # :nodoc:
29
- !Nokogiri::VERSION_INFO['libxml'].nil?
30
- end
10
+ def engine
11
+ defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'mri'
12
+ end
13
+
14
+ def loaded_parser_version
15
+ LIBXML_PARSER_VERSION.scan(/^(.*)(..)(..)$/).first.collect{ |j|
16
+ j.to_i
17
+ }.join(".")
18
+ end
19
+
20
+ def compiled_parser_version
21
+ LIBXML_VERSION
22
+ end
23
+
24
+ def libxml2?
25
+ defined?(LIBXML_VERSION)
26
+ end
27
+
28
+ def warnings
29
+ return [] unless libxml2?
31
30
 
32
- def self.ffi? # :nodoc:
33
- uses_libxml? && Nokogiri::VERSION_INFO['libxml']['binding'] == 'ffi'
31
+ if compiled_parser_version != loaded_parser_version
32
+ ["Nokogiri was built against LibXML version #{compiled_parser_version}, but has dynamically loaded #{loaded_parser_version}"]
33
+ else
34
+ []
35
+ end
36
+ end
37
+
38
+ def to_hash
39
+ hash_info = {}
40
+ hash_info['warnings'] = []
41
+ hash_info['nokogiri'] = Nokogiri::VERSION
42
+ hash_info['ruby'] = {}
43
+ hash_info['ruby']['version'] = ::RUBY_VERSION
44
+ hash_info['ruby']['platform'] = ::RUBY_PLATFORM
45
+ hash_info['ruby']['description'] = ::RUBY_DESCRIPTION
46
+ hash_info['ruby']['engine'] = engine
47
+ hash_info['ruby']['jruby'] = jruby? if jruby?
48
+
49
+ if libxml2?
50
+ hash_info['libxml'] = {}
51
+ hash_info['libxml']['binding'] = 'extension'
52
+ hash_info['libxml']['compiled'] = compiled_parser_version
53
+ hash_info['libxml']['loaded'] = loaded_parser_version
54
+ hash_info['warnings'] = warnings
55
+ end
56
+
57
+ hash_info
58
+ end
59
+
60
+ def to_markdown
61
+ begin
62
+ require 'psych'
63
+ rescue LoadError
64
+ end
65
+ require 'yaml'
66
+ "# Nokogiri (#{Nokogiri::VERSION})\n" +
67
+ YAML.dump(to_hash).each_line.map { |line| " #{line}" }.join
68
+ end
69
+
70
+ # FIXME: maybe switch to singleton?
71
+ @@instance = new
72
+ @@instance.warnings.each do |warning|
73
+ warn "WARNING: #{warning}"
74
+ end
75
+ def self.instance; @@instance; end
34
76
  end
35
77
 
36
- def self.jruby?
37
- false # for 1.5 compatibility
78
+ # More complete version information about libxml
79
+ VERSION_INFO = VersionInfo.instance.to_hash
80
+
81
+ def self.uses_libxml? # :nodoc:
82
+ VersionInfo.instance.libxml2?
38
83
  end
39
84
 
40
- def self.is_2_6_16? # :nodoc:
41
- Nokogiri::VERSION_INFO['libxml']['loaded'] <= '2.6.16'
85
+ def self.jruby? # :nodoc:
86
+ VersionInfo.instance.jruby?
42
87
  end
43
88
  end
@@ -8,7 +8,7 @@ module Nokogiri
8
8
  undef_method :content
9
9
  undef_method :namespace
10
10
  undef_method :namespace_definitions
11
- undef_method :line
11
+ undef_method :line if method_defined?(:line)
12
12
 
13
13
  def inspect
14
14
  "#<#{self.class.name}:#{sprintf("0x%x", object_id)} #{to_s.inspect}>"
@@ -327,6 +327,13 @@ module Nokogiri
327
327
  ###
328
328
  # Convert this Builder object to XML
329
329
  def to_xml(*args)
330
+ if Nokogiri.jruby?
331
+ options = args.first.is_a?(Hash) ? args.shift : {}
332
+ if !options[:save_with]
333
+ options[:save_with] = Node::SaveOptions::AS_BUILDER
334
+ end
335
+ args.insert(0, options)
336
+ end
330
337
  @doc.to_xml(*args)
331
338
  end
332
339
 
@@ -9,7 +9,7 @@ module Nokogiri
9
9
  # Nokogiri::XML::Node#xpath
10
10
  class Document < Nokogiri::XML::Node
11
11
  ##
12
- # Parse an XML file. +thing+ may be a String, or any object that
12
+ # Parse an XML file. +string_or_io+ may be a String, or any object that
13
13
  # responds to _read_ and _close_ such as an IO, or StringIO.
14
14
  # +url+ is resource where this document is located. +encoding+ is the
15
15
  # encoding that should be used when processing the document. +options+
@@ -205,6 +205,22 @@ module Nokogiri
205
205
  end
206
206
  alias :<< :add_child
207
207
 
208
+ ##
209
+ # +JRuby+
210
+ # Wraps Java's org.w3c.dom.document and returns Nokogiri::XML::Document
211
+ def self.wrap document
212
+ raise "JRuby only method" unless Nokogiri.jruby?
213
+ return wrapJavaDocument(document)
214
+ end
215
+
216
+ ##
217
+ # +JRuby+
218
+ # Returns Java's org.w3c.dom.document of this Document.
219
+ def to_java
220
+ raise "JRuby only method" unless Nokogiri.jruby?
221
+ return toJavaDocument()
222
+ end
223
+
208
224
  private
209
225
  def implied_xpath_context
210
226
  "/"
@@ -35,6 +35,13 @@ module Nokogiri
35
35
  # Convert this DocumentFragment to html
36
36
  # See Nokogiri::XML::NodeSet#to_html
37
37
  def to_html *args
38
+ if Nokogiri.jruby?
39
+ options = args.first.is_a?(Hash) ? args.shift : {}
40
+ if !options[:save_with]
41
+ options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_HTML
42
+ end
43
+ args.insert(0, options)
44
+ end
38
45
  children.to_html(*args)
39
46
  end
40
47
 
@@ -42,6 +49,13 @@ module Nokogiri
42
49
  # Convert this DocumentFragment to xhtml
43
50
  # See Nokogiri::XML::NodeSet#to_xhtml
44
51
  def to_xhtml *args
52
+ if Nokogiri.jruby?
53
+ options = args.first.is_a?(Hash) ? args.shift : {}
54
+ if !options[:save_with]
55
+ options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_XHTML
56
+ end
57
+ args.insert(0, options)
58
+ end
45
59
  children.to_xhtml(*args)
46
60
  end
47
61
 
@@ -6,7 +6,7 @@ module Nokogiri
6
6
  undef_method :content
7
7
  undef_method :namespace
8
8
  undef_method :namespace_definitions
9
- undef_method :line
9
+ undef_method :line if method_defined?(:line)
10
10
 
11
11
  def keys
12
12
  attributes.keys
@@ -3,7 +3,7 @@ module Nokogiri
3
3
  class ElementDecl < Nokogiri::XML::Node
4
4
  undef_method :namespace
5
5
  undef_method :namespace_definitions
6
- undef_method :line
6
+ undef_method :line if method_defined?(:line)
7
7
 
8
8
  def inspect
9
9
  "#<#{self.class.name}:#{sprintf("0x%x", object_id)} #{to_s.inspect}>"
@@ -5,7 +5,7 @@ module Nokogiri
5
5
  undef_method :attributes
6
6
  undef_method :namespace
7
7
  undef_method :namespace_definitions
8
- undef_method :line
8
+ undef_method :line if method_defined?(:line)
9
9
 
10
10
  def self.new name, doc, *args
11
11
  doc.create_entity(name, *args)
@@ -150,6 +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
154
 
154
155
  binds.each do |key,value|
155
156
  ctx.register_variable key.to_s, value
@@ -259,6 +260,8 @@ module Nokogiri
259
260
  # +node_or_tags+ can be a Nokogiri::XML::Node, a ::DocumentFragment, a ::NodeSet, or a string containing markup.
260
261
  #
261
262
  # Returns the reparented node (if +node_or_tags+ is a Node), or NodeSet (if +node_or_tags+ is a DocumentFragment, NodeSet, or string).
263
+ #
264
+ # Also see related method +<<+.
262
265
  def add_child node_or_tags
263
266
  node_or_tags = coerce(node_or_tags)
264
267
  if node_or_tags.is_a?(XML::NodeSet)
@@ -269,6 +272,17 @@ module Nokogiri
269
272
  node_or_tags
270
273
  end
271
274
 
275
+ ###
276
+ # Add +node_or_tags+ as a child of this Node.
277
+ # +node_or_tags+ can be a Nokogiri::XML::Node, a ::DocumentFragment, a ::NodeSet, or a string containing markup.
278
+ #
279
+ # Returns self, to support chaining of calls (e.g., root << child1 << child2)
280
+ #
281
+ # Also see related method +add_child+.
282
+ def << node_or_tags
283
+ add_child node_or_tags
284
+ self
285
+ end
272
286
  ###
273
287
  # Insert +node_or_tags+ before this Node (as a sibling).
274
288
  # +node_or_tags+ can be a Nokogiri::XML::Node, a ::DocumentFragment, a ::NodeSet, or a string containing markup.
@@ -309,7 +323,7 @@ module Nokogiri
309
323
  else
310
324
  pivot = self
311
325
  end
312
- node_or_tags.reverse.each { |n| pivot.send :add_next_sibling_node, n }
326
+ node_or_tags.reverse_each { |n| pivot.send :add_next_sibling_node, n }
313
327
  pivot.unlink if text?
314
328
  else
315
329
  add_next_sibling_node node_or_tags
@@ -366,7 +380,7 @@ module Nokogiri
366
380
  if node_or_tags.is_a?(XML::NodeSet)
367
381
  node_or_tags.each { |n| add_child_node n }
368
382
  else
369
- add_child node_or_tags
383
+ add_child_node node_or_tags
370
384
  end
371
385
  node_or_tags
372
386
  end
@@ -424,7 +438,6 @@ module Nokogiri
424
438
  alias :text :content
425
439
  alias :inner_text :content
426
440
  alias :has_attribute? :key?
427
- alias :<< :add_child
428
441
  alias :name :node_name
429
442
  alias :name= :node_name=
430
443
  alias :type :node_type
@@ -715,10 +728,11 @@ module Nokogiri
715
728
  def serialize *args, &block
716
729
  options = args.first.is_a?(Hash) ? args.shift : {
717
730
  :encoding => args[0],
718
- :save_with => args[1] || SaveOptions::FORMAT
731
+ :save_with => args[1]
719
732
  }
720
733
 
721
734
  encoding = options[:encoding] || document.encoding
735
+ options[:encoding] = encoding
722
736
 
723
737
  outstring = ""
724
738
  if encoding && outstring.respond_to?(:force_encoding)
@@ -738,9 +752,10 @@ module Nokogiri
738
752
  # use Node#to_xhtml instead.
739
753
  def to_html options = {}
740
754
  # FIXME: this is a hack around broken libxml versions
741
- return dump_html if %w[2 6] === LIBXML_VERSION.split('.')[0..1]
755
+ return dump_html if Nokogiri.uses_libxml? && %w[2 6] === LIBXML_VERSION.split('.')[0..1]
742
756
 
743
- options[:save_with] ||= SaveOptions::DEFAULT_HTML
757
+ options[:save_with] |= SaveOptions::DEFAULT_HTML if options[:save_with]
758
+ options[:save_with] = SaveOptions::DEFAULT_HTML unless options[:save_with]
744
759
  serialize(options)
745
760
  end
746
761
 
@@ -751,7 +766,8 @@ module Nokogiri
751
766
  #
752
767
  # See Node#write_to for a list of +options+
753
768
  def to_xml options = {}
754
- options[:save_with] ||= SaveOptions::DEFAULT_XML
769
+ options[:save_with] |= SaveOptions::DEFAULT_XML if options[:save_with]
770
+ options[:save_with] = SaveOptions::DEFAULT_XML unless options[:save_with]
755
771
  serialize(options)
756
772
  end
757
773
 
@@ -763,9 +779,10 @@ module Nokogiri
763
779
  # See Node#write_to for a list of +options+
764
780
  def to_xhtml options = {}
765
781
  # FIXME: this is a hack around broken libxml versions
766
- return dump_html if %w[2 6] === LIBXML_VERSION.split('.')[0..1]
782
+ return dump_html if Nokogiri.uses_libxml? && %w[2 6] === LIBXML_VERSION.split('.')[0..1]
767
783
 
768
- options[:save_with] ||= SaveOptions::DEFAULT_XHTML
784
+ options[:save_with] |= SaveOptions::DEFAULT_XHTML if options[:save_with]
785
+ options[:save_with] = SaveOptions::DEFAULT_XHTML unless options[:save_with]
769
786
  serialize(options)
770
787
  end
771
788
 
@@ -789,10 +806,14 @@ module Nokogiri
789
806
  def write_to io, *options
790
807
  options = options.first.is_a?(Hash) ? options.shift : {}
791
808
  encoding = options[:encoding] || options[0]
792
- save_options = options[:save_with] || options[1] || SaveOptions::FORMAT
809
+ if Nokogiri.jruby?
810
+ save_options = options[:save_with] || options[1]
811
+ indent_times = options[:indent] || 0
812
+ else
813
+ save_options = options[:save_with] || options[1] || SaveOptions::FORMAT
814
+ indent_times = options[:indent] || 2
815
+ end
793
816
  indent_text = options[:indent_text] || ' '
794
- indent_times = options[:indent] || 2
795
-
796
817
 
797
818
  config = SaveOptions.new(save_options.to_i)
798
819
  yield config if block_given?
@@ -806,7 +827,7 @@ module Nokogiri
806
827
  # See Node#write_to for a list of +options+
807
828
  def write_html_to io, options = {}
808
829
  # FIXME: this is a hack around broken libxml versions
809
- return (io << dump_html) if %w[2 6] === LIBXML_VERSION.split('.')[0..1]
830
+ return (io << dump_html) if Nokogiri.uses_libxml? && %w[2 6] === LIBXML_VERSION.split('.')[0..1]
810
831
 
811
832
  options[:save_with] ||= SaveOptions::DEFAULT_HTML
812
833
  write_to io, options
@@ -818,7 +839,7 @@ module Nokogiri
818
839
  # See Node#write_to for a list of +options+
819
840
  def write_xhtml_to io, options = {}
820
841
  # FIXME: this is a hack around broken libxml versions
821
- return (io << dump_html) if %w[2 6] === LIBXML_VERSION.split('.')[0..1]
842
+ return (io << dump_html) if Nokogiri.uses_libxml? && %w[2 6] === LIBXML_VERSION.split('.')[0..1]
822
843
 
823
844
  options[:save_with] ||= SaveOptions::DEFAULT_XHTML
824
845
  write_to io, options
@@ -855,7 +876,10 @@ module Nokogiri
855
876
  params -= [handler] if handler
856
877
 
857
878
  hashes = []
858
- hashes << params.pop while Hash === params.last || params.last.nil?
879
+ while Hash === params.last || params.last.nil?
880
+ hashes << params.pop
881
+ break if params.empty?
882
+ end
859
883
 
860
884
  ns, binds = hashes.reverse
861
885
 
@@ -6,7 +6,7 @@ module Nokogiri
6
6
  class SaveOptions
7
7
  # Format serialized xml
8
8
  FORMAT = 1
9
- # Do not include delcarations
9
+ # Do not include declarations
10
10
  NO_DECLARATION = 2
11
11
  # Do not include empty tags
12
12
  NO_EMPTY_TAGS = 4
@@ -19,10 +19,19 @@ module Nokogiri
19
19
  # Save as HTML
20
20
  AS_HTML = 64
21
21
 
22
- # the default for XML documents
23
- DEFAULT_XML = FORMAT | AS_XML
24
- # the default for HTML document
25
- DEFAULT_HTML = FORMAT | NO_DECLARATION | NO_EMPTY_TAGS | AS_HTML
22
+ if Nokogiri.jruby?
23
+ # Save builder created document
24
+ AS_BUILDER = 128
25
+ # the default for XML documents
26
+ DEFAULT_XML = AS_XML # https://github.com/tenderlove/nokogiri/issues/#issue/415
27
+ # the default for HTML document
28
+ DEFAULT_HTML = NO_DECLARATION | NO_EMPTY_TAGS | AS_HTML
29
+ else
30
+ # the default for XML documents
31
+ DEFAULT_XML = FORMAT | AS_XML
32
+ # the default for HTML document
33
+ DEFAULT_HTML = FORMAT | NO_DECLARATION | NO_EMPTY_TAGS | AS_HTML
34
+ end
26
35
  # the default for XHTML document
27
36
  DEFAULT_XHTML = FORMAT | NO_DECLARATION | NO_EMPTY_TAGS | AS_XHTML
28
37
 
@@ -273,6 +273,13 @@ module Nokogiri
273
273
  ###
274
274
  # Convert this NodeSet to HTML
275
275
  def to_html *args
276
+ if Nokogiri.jruby?
277
+ options = args.first.is_a?(Hash) ? args.shift : {}
278
+ if !options[:save_with]
279
+ options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_HTML
280
+ end
281
+ args.insert(0, options)
282
+ end
276
283
  map { |x| x.to_html(*args) }.join
277
284
  end
278
285
 
@@ -87,9 +87,9 @@ module Nokogiri
87
87
  ###
88
88
  # Get a list of attributes for the current node.
89
89
  def attributes
90
- Hash[*attribute_nodes.map { |node|
90
+ Hash[attribute_nodes.map { |node|
91
91
  [node.name, node.to_s]
92
- }.flatten].merge(namespaces || {})
92
+ }].merge(namespaces || {})
93
93
  end
94
94
 
95
95
  ###