nokogiri 1.3.3-x86-mingw32 → 1.4.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 (202) hide show
  1. data/CHANGELOG.ja.rdoc +48 -3
  2. data/CHANGELOG.rdoc +42 -0
  3. data/Manifest.txt +44 -29
  4. data/README.ja.rdoc +0 -2
  5. data/README.rdoc +4 -7
  6. data/Rakefile +14 -22
  7. data/bin/nokogiri +7 -5
  8. data/ext/nokogiri/extconf.rb +5 -21
  9. data/ext/nokogiri/html_document.c +14 -50
  10. data/ext/nokogiri/html_element_description.c +7 -7
  11. data/ext/nokogiri/html_entity_lookup.c +6 -4
  12. data/ext/nokogiri/html_sax_parser_context.c +92 -0
  13. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  14. data/ext/nokogiri/nokogiri.c +9 -3
  15. data/ext/nokogiri/nokogiri.h +16 -20
  16. data/ext/nokogiri/xml_attr.c +1 -1
  17. data/ext/nokogiri/xml_attribute_decl.c +67 -0
  18. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  19. data/ext/nokogiri/xml_cdata.c +6 -5
  20. data/ext/nokogiri/xml_comment.c +3 -2
  21. data/ext/nokogiri/xml_document.c +93 -23
  22. data/ext/nokogiri/xml_document_fragment.c +1 -3
  23. data/ext/nokogiri/xml_dtd.c +63 -6
  24. data/ext/nokogiri/xml_element_content.c +123 -0
  25. data/ext/nokogiri/xml_element_content.h +10 -0
  26. data/ext/nokogiri/xml_element_decl.c +69 -0
  27. data/ext/nokogiri/xml_element_decl.h +9 -0
  28. data/ext/nokogiri/xml_entity_decl.c +97 -0
  29. data/ext/nokogiri/xml_entity_decl.h +10 -0
  30. data/ext/nokogiri/xml_entity_reference.c +1 -1
  31. data/ext/nokogiri/xml_io.c +10 -3
  32. data/ext/nokogiri/xml_io.h +1 -0
  33. data/ext/nokogiri/xml_namespace.c +2 -2
  34. data/ext/nokogiri/xml_node.c +139 -34
  35. data/ext/nokogiri/xml_node.h +0 -1
  36. data/ext/nokogiri/xml_node_set.c +23 -16
  37. data/ext/nokogiri/xml_processing_instruction.c +1 -1
  38. data/ext/nokogiri/xml_reader.c +78 -50
  39. data/ext/nokogiri/xml_sax_parser.c +109 -168
  40. data/ext/nokogiri/xml_sax_parser.h +33 -0
  41. data/ext/nokogiri/xml_sax_parser_context.c +155 -0
  42. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  43. data/ext/nokogiri/xml_sax_push_parser.c +11 -6
  44. data/ext/nokogiri/xml_syntax_error.c +63 -12
  45. data/ext/nokogiri/xml_text.c +4 -3
  46. data/ext/nokogiri/xml_xpath.c +1 -1
  47. data/ext/nokogiri/xml_xpath_context.c +12 -25
  48. data/ext/nokogiri/xslt_stylesheet.c +3 -3
  49. data/lib/nokogiri.rb +4 -4
  50. data/lib/nokogiri/1.8/nokogiri.so +0 -0
  51. data/lib/nokogiri/1.9/nokogiri.so +0 -0
  52. data/lib/nokogiri/css/node.rb +1 -9
  53. data/lib/nokogiri/css/xpath_visitor.rb +11 -21
  54. data/lib/nokogiri/ffi/html/document.rb +0 -9
  55. data/lib/nokogiri/ffi/html/sax/parser_context.rb +38 -0
  56. data/lib/nokogiri/ffi/io_callbacks.rb +4 -2
  57. data/lib/nokogiri/ffi/libxml.rb +44 -10
  58. data/lib/nokogiri/ffi/structs/common_node.rb +1 -1
  59. data/lib/nokogiri/ffi/structs/xml_attribute.rb +27 -0
  60. data/lib/nokogiri/ffi/structs/xml_dtd.rb +3 -1
  61. data/lib/nokogiri/ffi/structs/xml_element.rb +26 -0
  62. data/lib/nokogiri/ffi/structs/xml_element_content.rb +17 -0
  63. data/lib/nokogiri/ffi/structs/xml_entity.rb +32 -0
  64. data/lib/nokogiri/ffi/structs/xml_enumeration.rb +12 -0
  65. data/lib/nokogiri/ffi/structs/xml_parser_context.rb +19 -0
  66. data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +4 -3
  67. data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +1 -1
  68. data/lib/nokogiri/ffi/xml/attribute_decl.rb +27 -0
  69. data/lib/nokogiri/ffi/xml/comment.rb +2 -2
  70. data/lib/nokogiri/ffi/xml/document.rb +29 -12
  71. data/lib/nokogiri/ffi/xml/document_fragment.rb +0 -5
  72. data/lib/nokogiri/ffi/xml/dtd.rb +14 -3
  73. data/lib/nokogiri/ffi/xml/element_content.rb +43 -0
  74. data/lib/nokogiri/ffi/xml/element_decl.rb +19 -0
  75. data/lib/nokogiri/ffi/xml/entity_decl.rb +27 -0
  76. data/lib/nokogiri/ffi/xml/node.rb +45 -5
  77. data/lib/nokogiri/ffi/xml/node_set.rb +1 -1
  78. data/lib/nokogiri/ffi/xml/reader.rb +45 -24
  79. data/lib/nokogiri/ffi/xml/sax/parser.rb +27 -34
  80. data/lib/nokogiri/ffi/xml/sax/parser_context.rb +67 -0
  81. data/lib/nokogiri/ffi/xml/sax/push_parser.rb +5 -4
  82. data/lib/nokogiri/ffi/xml/syntax_error.rb +31 -16
  83. data/lib/nokogiri/ffi/xml/text.rb +2 -2
  84. data/lib/nokogiri/html.rb +1 -0
  85. data/lib/nokogiri/html/document.rb +39 -24
  86. data/lib/nokogiri/html/sax/parser.rb +2 -2
  87. data/lib/nokogiri/html/sax/parser_context.rb +16 -0
  88. data/lib/nokogiri/version.rb +1 -1
  89. data/lib/nokogiri/xml.rb +6 -1
  90. data/lib/nokogiri/xml/attr.rb +5 -0
  91. data/lib/nokogiri/xml/attribute_decl.rb +18 -0
  92. data/lib/nokogiri/xml/builder.rb +121 -13
  93. data/lib/nokogiri/xml/character_data.rb +7 -0
  94. data/lib/nokogiri/xml/document.rb +43 -29
  95. data/lib/nokogiri/xml/document_fragment.rb +26 -6
  96. data/lib/nokogiri/xml/dtd.rb +5 -5
  97. data/lib/nokogiri/xml/element_content.rb +36 -0
  98. data/lib/nokogiri/xml/element_decl.rb +13 -0
  99. data/lib/nokogiri/xml/entity_decl.rb +15 -0
  100. data/lib/nokogiri/xml/fragment_handler.rb +22 -11
  101. data/lib/nokogiri/xml/namespace.rb +6 -0
  102. data/lib/nokogiri/xml/node.rb +33 -15
  103. data/lib/nokogiri/xml/node_set.rb +66 -44
  104. data/lib/nokogiri/xml/pp.rb +2 -0
  105. data/lib/nokogiri/xml/pp/character_data.rb +18 -0
  106. data/lib/nokogiri/xml/pp/node.rb +56 -0
  107. data/lib/nokogiri/xml/reader.rb +8 -0
  108. data/lib/nokogiri/xml/sax.rb +1 -1
  109. data/lib/nokogiri/xml/sax/document.rb +18 -1
  110. data/lib/nokogiri/xml/sax/parser.rb +15 -8
  111. data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
  112. data/lib/nokogiri/xml/sax/push_parser.rb +0 -3
  113. data/lib/nokogiri/xml/syntax_error.rb +4 -0
  114. data/lib/nokogiri/xslt/stylesheet.rb +1 -1
  115. data/test/css/test_nthiness.rb +1 -1
  116. data/test/css/test_parser.rb +1 -1
  117. data/test/css/test_tokenizer.rb +1 -1
  118. data/test/css/test_xpath_visitor.rb +1 -1
  119. data/test/ffi/test_document.rb +1 -1
  120. data/test/files/shift_jis.html +10 -0
  121. data/test/files/staff.dtd +10 -0
  122. data/test/helper.rb +12 -3
  123. data/test/html/sax/test_parser.rb +1 -1
  124. data/test/html/sax/test_parser_context.rb +48 -0
  125. data/test/html/test_builder.rb +8 -2
  126. data/test/html/test_document.rb +23 -1
  127. data/test/html/test_document_encoding.rb +15 -1
  128. data/test/html/test_document_fragment.rb +10 -1
  129. data/test/html/test_element_description.rb +1 -2
  130. data/test/html/test_named_characters.rb +1 -1
  131. data/test/html/test_node.rb +61 -1
  132. data/test/html/test_node_encoding.rb +27 -0
  133. data/test/test_convert_xpath.rb +1 -3
  134. data/test/test_css_cache.rb +1 -1
  135. data/test/test_gc.rb +1 -1
  136. data/test/test_memory_leak.rb +1 -1
  137. data/test/test_nokogiri.rb +3 -3
  138. data/test/test_reader.rb +29 -1
  139. data/test/test_xslt_transforms.rb +1 -1
  140. data/test/xml/node/test_save_options.rb +1 -1
  141. data/test/xml/node/test_subclass.rb +1 -1
  142. data/test/xml/sax/test_parser.rb +64 -3
  143. data/test/xml/sax/test_parser_context.rb +56 -0
  144. data/test/xml/sax/test_push_parser.rb +11 -1
  145. data/test/xml/test_attr.rb +1 -1
  146. data/test/xml/test_attribute_decl.rb +82 -0
  147. data/test/xml/test_builder.rb +95 -1
  148. data/test/xml/test_cdata.rb +1 -1
  149. data/test/xml/test_comment.rb +7 -1
  150. data/test/xml/test_document.rb +147 -6
  151. data/test/xml/test_document_encoding.rb +1 -1
  152. data/test/xml/test_document_fragment.rb +55 -5
  153. data/test/xml/test_dtd.rb +40 -5
  154. data/test/xml/test_dtd_encoding.rb +3 -1
  155. data/test/xml/test_element_content.rb +56 -0
  156. data/test/xml/test_element_decl.rb +73 -0
  157. data/test/xml/test_entity_decl.rb +83 -0
  158. data/test/xml/test_entity_reference.rb +1 -1
  159. data/test/xml/test_namespace.rb +21 -1
  160. data/test/xml/test_node.rb +70 -4
  161. data/test/xml/test_node_attributes.rb +1 -1
  162. data/test/xml/test_node_encoding.rb +1 -1
  163. data/test/xml/test_node_set.rb +136 -2
  164. data/test/xml/test_parse_options.rb +1 -1
  165. data/test/xml/test_processing_instruction.rb +1 -1
  166. data/test/xml/test_reader_encoding.rb +1 -1
  167. data/test/xml/test_relax_ng.rb +1 -1
  168. data/test/xml/test_schema.rb +1 -1
  169. data/test/xml/test_syntax_error.rb +27 -0
  170. data/test/xml/test_text.rb +13 -1
  171. data/test/xml/test_unparented_node.rb +1 -1
  172. data/test/xml/test_xpath.rb +1 -1
  173. metadata +55 -38
  174. data/ext/nokogiri/html_sax_parser.c +0 -57
  175. data/ext/nokogiri/html_sax_parser.h +0 -11
  176. data/lib/action-nokogiri.rb +0 -38
  177. data/lib/nokogiri/decorators.rb +0 -2
  178. data/lib/nokogiri/decorators/hpricot.rb +0 -3
  179. data/lib/nokogiri/decorators/hpricot/node.rb +0 -56
  180. data/lib/nokogiri/decorators/hpricot/node_set.rb +0 -54
  181. data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +0 -30
  182. data/lib/nokogiri/ffi/html/sax/parser.rb +0 -21
  183. data/lib/nokogiri/hpricot.rb +0 -92
  184. data/lib/nokogiri/xml/entity_declaration.rb +0 -11
  185. data/lib/nokogiri/xml/sax/legacy_handlers.rb +0 -65
  186. data/test/hpricot/files/basic.xhtml +0 -17
  187. data/test/hpricot/files/boingboing.html +0 -2266
  188. data/test/hpricot/files/cy0.html +0 -3653
  189. data/test/hpricot/files/immob.html +0 -400
  190. data/test/hpricot/files/pace_application.html +0 -1320
  191. data/test/hpricot/files/tenderlove.html +0 -16
  192. data/test/hpricot/files/uswebgen.html +0 -220
  193. data/test/hpricot/files/utf8.html +0 -1054
  194. data/test/hpricot/files/week9.html +0 -1723
  195. data/test/hpricot/files/why.xml +0 -19
  196. data/test/hpricot/load_files.rb +0 -11
  197. data/test/hpricot/test_alter.rb +0 -68
  198. data/test/hpricot/test_builder.rb +0 -20
  199. data/test/hpricot/test_parser.rb +0 -350
  200. data/test/hpricot/test_paths.rb +0 -15
  201. data/test/hpricot/test_preserved.rb +0 -77
  202. data/test/hpricot/test_xml.rb +0 -30
@@ -0,0 +1,2 @@
1
+ require 'nokogiri/xml/pp/node'
2
+ require 'nokogiri/xml/pp/character_data'
@@ -0,0 +1,18 @@
1
+ module Nokogiri
2
+ module XML
3
+ module PP
4
+ module CharacterData
5
+ def pretty_print pp # :nodoc:
6
+ nice_name = self.class.name.split('::').last
7
+ pp.group(2, "#(#{nice_name} ", ')') do
8
+ pp.pp text
9
+ end
10
+ end
11
+
12
+ def inspect # :nodoc:
13
+ "#<#{self.class.name}:#{sprintf("0x%x",object_id)} #{text.inspect}>"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,56 @@
1
+ module Nokogiri
2
+ module XML
3
+ module PP
4
+ module Node
5
+ def inspect # :nodoc:
6
+ attributes = inspect_attributes.reject { |x|
7
+ begin
8
+ attribute = send x
9
+ !attribute || (attribute.respond_to?(:empty?) && attribute.empty?)
10
+ rescue NoMethodError
11
+ true
12
+ end
13
+ }.map { |attribute|
14
+ "#{attribute.to_s.sub(/_\w+/, 's')}=#{send(attribute).inspect}"
15
+ }.join ' '
16
+ "#<#{self.class.name}:#{sprintf("0x%x", object_id)} #{attributes}>"
17
+ end
18
+
19
+ def pretty_print pp # :nodoc:
20
+ nice_name = self.class.name.split('::').last
21
+ pp.group(2, "#(#{nice_name}:#{sprintf("0x%x", object_id)} {", '})') do
22
+
23
+ pp.breakable
24
+ attrs = inspect_attributes.map { |t|
25
+ [t, send(t)] if respond_to?(t)
26
+ }.compact.find_all { |x|
27
+ if x.last
28
+ if [:attribute_nodes, :children].include? x.first
29
+ !x.last.empty?
30
+ else
31
+ true
32
+ end
33
+ end
34
+ }
35
+
36
+ pp.seplist(attrs) do |v|
37
+ if [:attribute_nodes, :children].include? v.first
38
+ pp.group(2, "#{v.first.to_s.sub(/_\w+$/, 's')} = [", "]") do
39
+ pp.breakable
40
+ pp.seplist(v.last) do |item|
41
+ pp.pp item
42
+ end
43
+ end
44
+ else
45
+ pp.text "#{v.first} = "
46
+ pp.pp v.last
47
+ end
48
+ end
49
+ pp.breakable
50
+
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -54,6 +54,14 @@ module Nokogiri
54
54
  }.flatten)].merge(namespaces || {})
55
55
  end
56
56
 
57
+ ###
58
+ # Get a list of attributes for the current node
59
+ def attribute_nodes
60
+ nodes = attr_nodes
61
+ nodes.each { |v| v.instance_variable_set(:@_r, self) }
62
+ nodes
63
+ end
64
+
57
65
  ###
58
66
  # Move the cursor through the document yielding each node to the block
59
67
  def each(&block)
@@ -1,4 +1,4 @@
1
1
  require 'nokogiri/xml/sax/document'
2
- require 'nokogiri/xml/sax/legacy_handlers'
2
+ require 'nokogiri/xml/sax/parser_context'
3
3
  require 'nokogiri/xml/sax/parser'
4
4
  require 'nokogiri/xml/sax/push_parser'
@@ -68,6 +68,11 @@ module Nokogiri
68
68
  # You can use this event handler for any SAX style parser included with
69
69
  # Nokogiri. See Nokogiri::XML::SAX, and Nokogiri::HTML::SAX.
70
70
  class Document
71
+ ###
72
+ # Called when an XML declaration is parsed
73
+ def xmldecl version, encoding, standalone
74
+ end
75
+
71
76
  ###
72
77
  # Called when document starts parsing
73
78
  def start_document
@@ -97,7 +102,16 @@ module Nokogiri
97
102
  # +prefix+ is the namespace prefix for the element
98
103
  # +uri+ is the associated namespace URI
99
104
  # +ns+ is a hash of namespace prefix:urls associated with the element
100
- def start_element_namespace name, attrs = {}, prefix = nil, uri = nil, ns = {}
105
+ def start_element_namespace name, attrs = [], prefix = nil, uri = nil, ns = []
106
+ ###
107
+ # Deal with SAX v1 interface
108
+ name = [prefix, name].compact.join(':')
109
+ attributes = ns.map { |ns_prefix,ns_uri|
110
+ [['xmlns', ns_prefix].compact.join(':'), ns_uri]
111
+ } + attrs.map { |attr|
112
+ [[attr.prefix, attr.localname].compact.join(':'), attr.value]
113
+ }.flatten
114
+ start_element name, attributes
101
115
  end
102
116
 
103
117
  ###
@@ -106,6 +120,9 @@ module Nokogiri
106
120
  # +prefix+ is the namespace prefix associated with the element
107
121
  # +uri+ is the associated namespace URI
108
122
  def end_element_namespace name, prefix = nil, uri = nil
123
+ ###
124
+ # Deal with SAX v1 interface
125
+ end_element [prefix, name].compact.join(':')
109
126
  end
110
127
 
111
128
  ###
@@ -67,7 +67,7 @@ module Nokogiri
67
67
  attr_accessor :encoding
68
68
 
69
69
  # Create a new Parser with +doc+ and +encoding+
70
- def initialize(doc = Nokogiri::XML::SAX::Document.new, encoding = 'ASCII')
70
+ def initialize doc = Nokogiri::XML::SAX::Document.new, encoding = 'UTF-8'
71
71
  @encoding = encoding
72
72
  @document = doc
73
73
  @warned = false
@@ -76,11 +76,11 @@ module Nokogiri
76
76
  ###
77
77
  # Parse given +thing+ which may be a string containing xml, or an
78
78
  # IO object.
79
- def parse thing
79
+ def parse thing, &block
80
80
  if thing.respond_to?(:read) && thing.respond_to?(:close)
81
- parse_io(thing)
81
+ parse_io(thing, &block)
82
82
  else
83
- parse_memory(thing)
83
+ parse_memory(thing, &block)
84
84
  end
85
85
  end
86
86
 
@@ -88,7 +88,9 @@ module Nokogiri
88
88
  # Parse given +io+
89
89
  def parse_io io, encoding = 'ASCII'
90
90
  @encoding = encoding
91
- native_parse_io io, ENCODINGS[@encoding] || ENCODINGS['ASCII']
91
+ ctx = ParserContext.io(io, ENCODINGS[encoding])
92
+ yield ctx if block_given?
93
+ ctx.parse_with self
92
94
  end
93
95
 
94
96
  ###
@@ -97,11 +99,16 @@ module Nokogiri
97
99
  raise ArgumentError unless filename
98
100
  raise Errno::ENOENT unless File.exists?(filename)
99
101
  raise Errno::EISDIR if File.directory?(filename)
100
- native_parse_file filename
102
+ ctx = ParserContext.file filename
103
+ yield ctx if block_given?
104
+ ctx.parse_with self
101
105
  end
102
106
 
103
- private
104
- include Nokogiri::XML::SAX::LegacyHandlers
107
+ def parse_memory data
108
+ ctx = ParserContext.memory data
109
+ yield ctx if block_given?
110
+ ctx.parse_with self
111
+ end
105
112
  end
106
113
  end
107
114
  end
@@ -0,0 +1,16 @@
1
+ module Nokogiri
2
+ module XML
3
+ module SAX
4
+ ###
5
+ # Context for XML SAX parsers. This class is usually not instantiated
6
+ # by the user. Instead, you should be looking at
7
+ # Nokogiri::XML::SAX::Parser
8
+ class ParserContext
9
+ def self.new thing, encoding = 'UTF-8'
10
+ [:read, :close].all? { |x| thing.respond_to?(x) } ?
11
+ io(thing, Parser::ENCODINGS[encoding]) : memory(thing)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -54,9 +54,6 @@ module Nokogiri
54
54
  def finish
55
55
  write '', true
56
56
  end
57
-
58
- private
59
- include Nokogiri::XML::SAX::LegacyHandlers
60
57
  end
61
58
  end
62
59
  end
@@ -4,6 +4,10 @@ module Nokogiri
4
4
  # This class provides information about XML SyntaxErrors. These
5
5
  # exceptions are typically stored on Nokogiri::XML::Document#errors.
6
6
  class SyntaxError < ::Nokogiri::SyntaxError
7
+ def initialize message
8
+ self.message = message
9
+ end
10
+
7
11
  ###
8
12
  # return true if this is a non error
9
13
  def none?
@@ -18,7 +18,7 @@ module Nokogiri
18
18
  # +params+ is an array of strings used as XSLT parameters.
19
19
  # returns serialized document
20
20
  def apply_to document, params = []
21
- serialize(transform(document, params))
21
+ transform(document, params).to_s
22
22
  end
23
23
  end
24
24
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
1
+ require "helper"
2
2
 
3
3
  module Nokogiri
4
4
  module CSS
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
1
+ require "helper"
2
2
 
3
3
  module Nokogiri
4
4
  module CSS
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
3
+ require "helper"
4
4
 
5
5
  module Nokogiri
6
6
  module CSS
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
1
+ require "helper"
2
2
 
3
3
  module Nokogiri
4
4
  module CSS
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "helper"))
1
+ require "helper"
2
2
 
3
3
  if defined?(Nokogiri::LibXML)
4
4
 
@@ -0,0 +1,10 @@
1
+ <html>
2
+ <head>
3
+ <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
4
+ <title>����ɂ��́I</title>
5
+ </head>
6
+ <body>
7
+ <h1>This is a Shift_JIS File</h1>
8
+ <h2>����ɂ��́I</h2>
9
+ </body>
10
+ </html>
@@ -0,0 +1,10 @@
1
+ <!ENTITY ent1 "es">
2
+ <!ENTITY ent2 "1900 Dallas Road">
3
+ <!ENTITY ent3 "Texas">
4
+ <!ENTITY ent4 "<entElement domestic='Yes'>Element data</entElement><?PItarget PIdata?>">
5
+ <!ENTITY ent5 PUBLIC "entityURI" "entityFile" NDATA notation1>
6
+ <!ENTITY ent1 "This entity should be discarded">
7
+ <!ELEMENT br EMPTY>
8
+ <!ATTLIST br width CDATA "0">
9
+ <!NOTATION notation1 PUBLIC "notation1File">
10
+ <!NOTATION notation2 SYSTEM "notation2File">
data/test/helper.rb CHANGED
@@ -1,8 +1,10 @@
1
- Process.setrlimit(Process::RLIMIT_CORE, Process::RLIM_INFINITY) unless RUBY_PLATFORM =~ /(java|mswin|mingw)/i
1
+ #Process.setrlimit(Process::RLIMIT_CORE, Process::RLIM_INFINITY) unless RUBY_PLATFORM =~ /(java|mswin|mingw)/i
2
2
  $VERBOSE = true
3
3
  require 'rubygems'
4
4
  require 'test/unit'
5
+ require 'fileutils'
5
6
  require 'tempfile'
7
+ require 'pp'
6
8
 
7
9
  %w(../lib ../ext).each do |path|
8
10
  $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), path)))
@@ -14,7 +16,7 @@ warn "#{__FILE__}:#{__LINE__}: libxml version info: #{Nokogiri::VERSION_INFO.ins
14
16
 
15
17
  module Nokogiri
16
18
  class TestCase < Test::Unit::TestCase
17
- ASSETS_DIR = File.join(File.dirname(__FILE__), 'files')
19
+ ASSETS_DIR = File.expand_path File.join(File.dirname(__FILE__), 'files')
18
20
  XML_FILE = File.join(ASSETS_DIR, 'staff.xml')
19
21
  XSLT_FILE = File.join(ASSETS_DIR, 'staff.xslt')
20
22
  EXSLT_FILE = File.join(ASSETS_DIR, 'exslt.xslt')
@@ -22,6 +24,7 @@ module Nokogiri
22
24
  HTML_FILE = File.join(ASSETS_DIR, 'tlm.html')
23
25
  NICH_FILE = File.join(ASSETS_DIR, '2ch.html')
24
26
  SHIFT_JIS_XML = File.join(ASSETS_DIR, 'shift_jis.xml')
27
+ SHIFT_JIS_HTML = File.join(ASSETS_DIR, 'shift_jis.html')
25
28
  PO_XML_FILE = File.join(ASSETS_DIR, 'po.xml')
26
29
  PO_SCHEMA_FILE = File.join(ASSETS_DIR, 'po.xsd')
27
30
  ADDRESS_SCHEMA_FILE = File.join(ASSETS_DIR, 'address_book.rlx')
@@ -39,7 +42,7 @@ module Nokogiri
39
42
  def teardown
40
43
  if ENV['NOKOGIRI_GC']
41
44
  STDOUT.putc '!'
42
- GC.start
45
+ GC.start
43
46
  end
44
47
  end
45
48
 
@@ -63,6 +66,12 @@ module Nokogiri
63
66
  attr_reader :end_elements, :end_document_called
64
67
  attr_reader :data, :comments, :cdata_blocks, :start_elements_namespace
65
68
  attr_reader :errors, :warnings, :end_elements_namespace
69
+ attr_reader :xmldecls
70
+
71
+ def xmldecl version, encoding, standalone
72
+ @xmldecls = [version, encoding, standalone].compact
73
+ super
74
+ end
66
75
 
67
76
  def start_document
68
77
  @start_document_called = true
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', "helper"))
1
+ require "helper"
2
2
 
3
3
  module Nokogiri
4
4
  module HTML
@@ -0,0 +1,48 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require "helper"
4
+
5
+ module Nokogiri
6
+ module HTML
7
+ module SAX
8
+ class TestParserContext < Nokogiri::SAX::TestCase
9
+ def test_from_io
10
+ assert_nothing_raised do
11
+ ctx = ParserContext.new StringIO.new('fo'), 'UTF-8'
12
+ end
13
+ end
14
+
15
+ def test_from_string
16
+ assert_nothing_raised do
17
+ ctx = ParserContext.new 'blah blah'
18
+ end
19
+ end
20
+
21
+ def test_parse_with
22
+ ctx = ParserContext.new 'blah'
23
+ assert_raises ArgumentError do
24
+ ctx.parse_with nil
25
+ end
26
+ end
27
+
28
+ def test_parse_with_sax_parser
29
+ assert_nothing_raised do
30
+ xml = "<root />"
31
+ ctx = ParserContext.new xml
32
+ parser = Parser.new Doc.new
33
+ ctx.parse_with parser
34
+ end
35
+ end
36
+
37
+ def test_from_file
38
+ assert_nothing_raised do
39
+ ctx = ParserContext.file HTML_FILE, 'UTF-8'
40
+ parser = Parser.new Doc.new
41
+ ctx.parse_with parser
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
@@ -1,8 +1,14 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
1
+ require "helper"
2
2
 
3
3
  module Nokogiri
4
4
  module HTML
5
5
  class TestBuilder < Nokogiri::TestCase
6
+ def test_top_level_function_builds
7
+ foo = nil
8
+ Nokogiri() { |xml| foo = xml }
9
+ assert_instance_of Nokogiri::HTML::Builder, foo
10
+ end
11
+
6
12
  def test_builder_with_explicit_tags
7
13
  html_doc = Nokogiri::HTML::Builder.new {
8
14
  div.slide(:class => 'another_class') {
@@ -119,7 +125,7 @@ module Nokogiri
119
125
  assert_equal('<html><body><b>bold tag</b></body></html>',
120
126
  builder.doc.root.to_html.chomp.gsub(/>\s*</, '><'))
121
127
  end
122
-
128
+
123
129
  def test_instance_eval_with_delegation_to_block_context
124
130
  class << self
125
131
  def foo
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
1
+ require "helper"
2
2
 
3
3
  module Nokogiri
4
4
  module HTML
@@ -8,6 +8,11 @@ module Nokogiri
8
8
  @html = Nokogiri::HTML.parse(File.read(HTML_FILE))
9
9
  end
10
10
 
11
+ def test_fragment
12
+ fragment = @html.fragment
13
+ assert_equal 0, fragment.children.length
14
+ end
15
+
11
16
  def test_document_takes_config_block
12
17
  options = nil
13
18
  Nokogiri::HTML(File.read(HTML_FILE), HTML_FILE) do |cfg|
@@ -66,8 +71,12 @@ module Nokogiri
66
71
  assert_equal @html.to_s, html.to_s
67
72
  end
68
73
 
74
+ ###
75
+ # Nokogiri::HTML returns an empty Document when given a blank string GH#11
69
76
  def test_empty_string_returns_empty_doc
70
77
  doc = Nokogiri::HTML('')
78
+ assert_instance_of Nokogiri::HTML::Document, doc
79
+ assert_nil doc.root
71
80
  end
72
81
 
73
82
  unless %w[2 6] === LIBXML_VERSION.split('.')[0..1]
@@ -109,6 +118,14 @@ module Nokogiri
109
118
  assert_equal 'EUC-JP', @html.meta_encoding
110
119
  end
111
120
 
121
+ def test_meta_encoding_without_head
122
+ html = Nokogiri::HTML('<html><body>foo</body></html>')
123
+ assert_nil html.meta_encoding
124
+
125
+ html.meta_encoding = 'EUC-JP'
126
+ assert_nil html.meta_encoding
127
+ end
128
+
112
129
  def test_root_node_parent_is_document
113
130
  parent = @html.root.parent
114
131
  assert_equal @html, parent
@@ -295,6 +312,11 @@ module Nokogiri
295
312
  assert_equal('<p>Helloworld!</p>', node.inner_html.gsub(/\s/, ''))
296
313
  end
297
314
 
315
+ def test_round_trip
316
+ doc = Nokogiri::HTML(@html.inner_html)
317
+ assert_equal @html.root.to_html, doc.root.to_html
318
+ end
319
+
298
320
  def test_fragment_contains_text_node
299
321
  fragment = Nokogiri::HTML.fragment('fooo')
300
322
  assert_equal 1, fragment.children.length