nokogiri 1.5.2-java → 1.5.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 (70) hide show
  1. data/CHANGELOG.ja.rdoc +35 -0
  2. data/CHANGELOG.rdoc +37 -2
  3. data/Manifest.txt +11 -3
  4. data/README.rdoc +1 -1
  5. data/ROADMAP.md +86 -0
  6. data/{nokogiri_help_responses.md → STANDARD_RESPONSES.md} +11 -4
  7. data/Y_U_NO_GEMSPEC.md +155 -0
  8. data/build_all +58 -0
  9. data/ext/java/nokogiri/HtmlDocument.java +10 -1
  10. data/ext/java/nokogiri/XmlAttr.java +11 -1
  11. data/ext/java/nokogiri/XmlDocument.java +4 -0
  12. data/ext/java/nokogiri/XmlNamespace.java +25 -0
  13. data/ext/java/nokogiri/XmlNode.java +6 -6
  14. data/ext/java/nokogiri/XmlReader.java +19 -4
  15. data/ext/java/nokogiri/XmlSaxPushParser.java +88 -57
  16. data/ext/java/nokogiri/XmlSyntaxError.java +15 -3
  17. data/ext/java/nokogiri/XmlXpathContext.java +3 -3
  18. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +2 -1
  19. data/ext/java/nokogiri/internals/NokogiriHelpers.java +89 -1
  20. data/ext/java/nokogiri/internals/ParserContext.java +23 -2
  21. data/ext/java/nokogiri/internals/SaveContextVisitor.java +18 -1
  22. data/ext/java/nokogiri/internals/XmlDomParserContext.java +2 -3
  23. data/ext/nokogiri/extconf.rb +1 -1
  24. data/ext/nokogiri/xml_io.c +1 -1
  25. data/ext/nokogiri/xml_namespace.c +0 -6
  26. data/ext/nokogiri/xml_node.c +11 -11
  27. data/ext/nokogiri/xml_node_set.c +1 -1
  28. data/ext/nokogiri/xml_xpath_context.c +20 -16
  29. data/ext/nokogiri/xml_xpath_context.h +1 -0
  30. data/ext/nokogiri/xslt_stylesheet.c +7 -64
  31. data/lib/nokogiri/css/node.rb +3 -0
  32. data/lib/nokogiri/css/parser.rb +244 -203
  33. data/lib/nokogiri/css/parser.y +20 -2
  34. data/lib/nokogiri/css/xpath_visitor.rb +2 -2
  35. data/lib/nokogiri/html/document.rb +2 -1
  36. data/lib/nokogiri/html/element_description_defaults.rb +1 -1
  37. data/lib/nokogiri/nokogiri.jar +0 -0
  38. data/lib/nokogiri/version.rb +1 -1
  39. data/lib/nokogiri/xml/document.rb +1 -1
  40. data/lib/nokogiri/xml/parse_options.rb +2 -2
  41. data/lib/nokogiri/xml/sax/document.rb +1 -1
  42. data/lib/nokogiri/xml/sax/parser.rb +1 -1
  43. data/lib/nokogiri/xslt.rb +1 -1
  44. data/test/css/test_parser.rb +38 -0
  45. data/test/files/to_be_xincluded.xml +2 -0
  46. data/test/files/xinclude.xml +4 -0
  47. data/test/helper.rb +18 -45
  48. data/test/html/sax/test_parser.rb +5 -3
  49. data/test/html/sax/test_parser_context.rb +8 -10
  50. data/test/html/test_document.rb +19 -5
  51. data/test/html/test_node.rb +2 -4
  52. data/test/test_reader.rb +63 -0
  53. data/test/test_xslt_transforms.rb +3 -1
  54. data/test/xml/sax/test_parser_context.rb +10 -17
  55. data/test/xml/sax/test_push_parser.rb +1 -0
  56. data/test/xml/test_attr.rb +5 -6
  57. data/test/xml/test_builder.rb +5 -6
  58. data/test/xml/test_cdata.rb +1 -3
  59. data/test/xml/test_document.rb +11 -14
  60. data/test/xml/test_document_encoding.rb +3 -1
  61. data/test/xml/test_document_fragment.rb +27 -8
  62. data/test/xml/test_node.rb +21 -0
  63. data/test/xml/test_node_set.rb +2 -2
  64. data/test/xml/test_text.rb +1 -3
  65. data/test/xml/test_unparented_node.rb +2 -2
  66. data/test/xml/test_xpath.rb +15 -6
  67. data/test/xslt/test_custom_functions.rb +35 -0
  68. data/test_all +84 -0
  69. metadata +13 -8
  70. data/ext/java/nokogiri/internals/PushInputStream.java +0 -411
@@ -9,12 +9,13 @@ rule
9
9
  : selector COMMA simple_selector_1toN {
10
10
  result = [val.first, val.last].flatten
11
11
  }
12
+ | prefixless_combinator_selector { result = val.flatten }
12
13
  | simple_selector_1toN { result = val.flatten }
13
14
  ;
14
15
  combinator
15
16
  : PLUS { result = :DIRECT_ADJACENT_SELECTOR }
16
17
  | GREATER { result = :CHILD_SELECTOR }
17
- | TILDE { result = :PRECEDING_SELECTOR }
18
+ | TILDE { result = :FOLLOWING_SELECTOR }
18
19
  | S { result = :DESCENDANT_SELECTOR }
19
20
  | DOUBLESLASH { result = :DESCENDANT_SELECTOR }
20
21
  | SLASH { result = :CHILD_SELECTOR }
@@ -59,6 +60,11 @@ rule
59
60
  )
60
61
  }
61
62
  ;
63
+ prefixless_combinator_selector
64
+ : combinator simple_selector_1toN {
65
+ result = Node.new(val.first, [nil, val.last])
66
+ }
67
+ ;
62
68
  simple_selector_1toN
63
69
  : simple_selector combinator simple_selector_1toN {
64
70
  result = Node.new(val[1], [val.first, val.last])
@@ -88,7 +94,7 @@ rule
88
94
  |
89
95
  ;
90
96
  attrib
91
- : LSQUARE namespaced_ident attrib_val_0or1 RSQUARE {
97
+ : LSQUARE attrib_name attrib_val_0or1 RSQUARE {
92
98
  result = Node.new(:ATTRIBUTE_CONDITION,
93
99
  [val[1]] + (val[2] || [])
94
100
  )
@@ -105,6 +111,18 @@ rule
105
111
  )
106
112
  }
107
113
  ;
114
+ attrib_name
115
+ : namespace '|' IDENT {
116
+ result = Node.new(:ELEMENT_NAME,
117
+ [[val.first, val.last].compact.join(':')]
118
+ )
119
+ }
120
+ | IDENT {
121
+ # Default namespace is not applied to attributes.
122
+ # So we don't add prefix "xmlns:" as in namespaced_ident.
123
+ result = Node.new(:ELEMENT_NAME, [val.first])
124
+ }
125
+ ;
108
126
  function
109
127
  : FUNCTION RPAREN {
110
128
  result = Node.new(:FUNCTION, [val.first.strip])
@@ -126,13 +126,13 @@ module Nokogiri
126
126
  {
127
127
  'combinator' => ' and ',
128
128
  'direct_adjacent_selector' => "/following-sibling::*[1]/self::",
129
- 'preceding_selector' => "/following-sibling::",
129
+ 'following_selector' => "/following-sibling::",
130
130
  'descendant_selector' => '//',
131
131
  'child_selector' => '/',
132
132
  }.each do |k,v|
133
133
  class_eval %{
134
134
  def visit_#{k} node
135
- "\#{node.value.first.accept(self)}#{v}\#{node.value.last.accept(self)}"
135
+ "\#{node.value.first.accept(self) if node.value.first}#{v}\#{node.value.last.accept(self)}"
136
136
  end
137
137
  }
138
138
  end
@@ -6,7 +6,8 @@ module Nokogiri
6
6
  # then nil is returned.
7
7
  def meta_encoding
8
8
  meta = meta_content_type and
9
- /charset\s*=\s*([\w-]+)/i.match(meta['content'])[1]
9
+ match = /charset\s*=\s*([\w-]+)/i.match(meta['content']) and
10
+ match[1]
10
11
  end
11
12
 
12
13
  ###
@@ -3,7 +3,7 @@ module Nokogiri
3
3
  class ElementDescription
4
4
 
5
5
  # Methods are defined protected by method_defined? because at
6
- # this point the C-library or Java library is alraedy loaded,
6
+ # this point the C-library or Java library is already loaded,
7
7
  # and we don't want to clobber any methods that have been
8
8
  # defined there.
9
9
 
Binary file
@@ -1,6 +1,6 @@
1
1
  module Nokogiri
2
2
  # The version of Nokogiri you are using
3
- VERSION = '1.5.2'
3
+ VERSION = '1.5.3'
4
4
 
5
5
  class VersionInfo # :nodoc:
6
6
  def jruby?
@@ -132,7 +132,7 @@ module Nokogiri
132
132
  # in the hash.
133
133
  #
134
134
  # Note this is a very expensive operation in current implementation, as it
135
- # traverses the entire graph, and also has to bring each node accross the
135
+ # traverses the entire graph, and also has to bring each node across the
136
136
  # libxml bridge into a ruby object.
137
137
  def collect_namespaces
138
138
  ns = {}
@@ -25,11 +25,11 @@ module Nokogiri
25
25
  NOBLANKS = 1 << 8
26
26
  # use the SAX1 interface internally
27
27
  SAX1 = 1 << 9
28
- # Implement XInclude substitition
28
+ # Implement XInclude substitution
29
29
  XINCLUDE = 1 << 10
30
30
  # Forbid network access
31
31
  NONET = 1 << 11
32
- # Do not reuse the context dictionnary
32
+ # Do not reuse the context dictionary
33
33
  NODICT = 1 << 12
34
34
  # remove redundant namespaces declarations
35
35
  NSCLEAN = 1 << 13
@@ -33,7 +33,7 @@ module Nokogiri
33
33
  # parser = Nokogiri::XML::SAX::Parser.new(MyDocument.new)
34
34
  #
35
35
  # # Feed the parser some XML
36
- # parser.parse(File.read(ARGV[0], 'rb'))
36
+ # parser.parse(File.open(ARGV[0]))
37
37
  #
38
38
  # Now my document handler will be called when each node starts, and when
39
39
  # then document ends. To see what kinds of events are available, take
@@ -25,7 +25,7 @@ module Nokogiri
25
25
  # parser = Nokogiri::XML::SAX::Parser.new(MyDoc.new)
26
26
  #
27
27
  # # Send some XML to the parser
28
- # parser.parse(File.read(ARGV[0]))
28
+ # parser.parse(File.open(ARGV[0]))
29
29
  #
30
30
  # For more information about SAX parsers, see Nokogiri::XML::SAX. Also
31
31
  # see Nokogiri::XML::SAX::Document for the available events.
@@ -15,7 +15,7 @@ module Nokogiri
15
15
  end
16
16
 
17
17
  ###
18
- # See Nokogiri::XSLT::Stylesheet for creating and maniuplating
18
+ # See Nokogiri::XSLT::Stylesheet for creating and manipulating
19
19
  # Stylesheet object.
20
20
  module XSLT
21
21
  class << self
@@ -6,6 +6,10 @@ module Nokogiri
6
6
  def setup
7
7
  super
8
8
  @parser = Nokogiri::CSS::Parser.new
9
+ @parser_with_ns = Nokogiri::CSS::Parser.new({
10
+ "xmlns" => "http://default.example.com/",
11
+ "hoge" => "http://hoge.example.com/",
12
+ })
9
13
  end
10
14
 
11
15
  def test_extra_single_quote
@@ -214,6 +218,33 @@ module Nokogiri
214
218
  @parser.parse("E + F G")
215
219
  end
216
220
 
221
+ def test_child_selector
222
+ assert_xpath("//a//b/i", @parser.parse('a b>i'))
223
+ assert_xpath("//a//b/i", @parser.parse('a b > i'))
224
+ assert_xpath("//a/b/i", @parser.parse('a > b > i'))
225
+ end
226
+
227
+ def test_prefixless_child_selector
228
+ assert_xpath("./a", @parser.parse('>a'))
229
+ assert_xpath("./a", @parser.parse('> a'))
230
+ assert_xpath("./a//b/i", @parser.parse('>a b>i'))
231
+ assert_xpath("./a/b/i", @parser.parse('> a > b > i'))
232
+ end
233
+
234
+ def test_prefixless_preceding_sibling_selector
235
+ assert_xpath("./following-sibling::a", @parser.parse('~a'))
236
+ assert_xpath("./following-sibling::a", @parser.parse('~ a'))
237
+ assert_xpath("./following-sibling::a//b/following-sibling::i", @parser.parse('~a b~i'))
238
+ assert_xpath("./following-sibling::a//b/following-sibling::i", @parser.parse('~ a b ~ i'))
239
+ end
240
+
241
+ def test_prefixless_direct_adjacent_selector
242
+ assert_xpath("./following-sibling::*[1]/self::a", @parser.parse('+a'))
243
+ assert_xpath("./following-sibling::*[1]/self::a", @parser.parse('+ a'))
244
+ assert_xpath("./following-sibling::*[1]/self::a/following-sibling::*[1]/self::b", @parser.parse('+a+b'))
245
+ assert_xpath("./following-sibling::*[1]/self::a/following-sibling::*[1]/self::b", @parser.parse('+ a + b'))
246
+ end
247
+
217
248
  def test_attribute
218
249
  assert_xpath "//h1[@a = 'Tender Lovemaking']",
219
250
  @parser.parse("h1[a='Tender Lovemaking']")
@@ -292,6 +323,13 @@ module Nokogiri
292
323
  # assert_xpath ['//x/y', '//y/z'], @parser.parse('x > y | y > z')
293
324
  end
294
325
 
326
+ def test_attributes_with_namespace
327
+ ## Default namespace is not applied to attributes.
328
+ ## So this must be @class, not @xmlns:class.
329
+ assert_xpath "//xmlns:a[@class = 'bar']", @parser_with_ns.parse("a[class='bar']")
330
+ assert_xpath "//xmlns:a[@hoge:class = 'bar']", @parser_with_ns.parse("a[hoge|class='bar']")
331
+ end
332
+
295
333
  def assert_xpath expecteds, asts
296
334
  expecteds = [expecteds].flatten
297
335
  expecteds.zip(asts).each do |expected, actual|
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <included>this snippet is to be included from xinclude.xml</included>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <test xmlns:xi="http://www.w3.org/2001/XInclude">
3
+ <xi:include href="to_be_xincluded.xml"/>
4
+ </test>
@@ -11,25 +11,25 @@ warn "#{__FILE__}:#{__LINE__}: version info: #{Nokogiri::VERSION_INFO.inspect}"
11
11
 
12
12
  module Nokogiri
13
13
  class TestCase < MiniTest::Spec
14
- ASSETS_DIR = File.expand_path File.join(File.dirname(__FILE__), 'files')
15
- XML_FILE = File.join(ASSETS_DIR, 'staff.xml')
16
- XSLT_FILE = File.join(ASSETS_DIR, 'staff.xslt')
17
- EXSLT_FILE = File.join(ASSETS_DIR, 'exslt.xslt')
18
- EXML_FILE = File.join(ASSETS_DIR, 'exslt.xml')
19
- HTML_FILE = File.join(ASSETS_DIR, 'tlm.html')
20
- NICH_FILE = File.join(ASSETS_DIR, '2ch.html')
21
- SHIFT_JIS_XML = File.join(ASSETS_DIR, 'shift_jis.xml')
22
- SHIFT_JIS_HTML = File.join(ASSETS_DIR, 'shift_jis.html')
23
- ENCODING_XHTML_FILE = File.join(ASSETS_DIR, 'encoding.xhtml')
24
- ENCODING_HTML_FILE = File.join(ASSETS_DIR, 'encoding.html')
25
- NOENCODING_FILE = File.join(ASSETS_DIR, 'noencoding.html')
26
- METACHARSET_FILE = File.join(ASSETS_DIR, 'metacharset.html')
27
- PO_XML_FILE = File.join(ASSETS_DIR, 'po.xml')
28
- PO_SCHEMA_FILE = File.join(ASSETS_DIR, 'po.xsd')
14
+ ASSETS_DIR = File.expand_path File.join(File.dirname(__FILE__), 'files')
29
15
  ADDRESS_SCHEMA_FILE = File.join(ASSETS_DIR, 'address_book.rlx')
30
- ADDRESS_XML_FILE = File.join(ASSETS_DIR, 'address_book.xml')
31
- SNUGGLES_FILE = File.join(ASSETS_DIR, 'snuggles.xml')
32
- XML_XINCLUDE_FILE = File.join(ASSETS_DIR, 'xinclude.xml')
16
+ ADDRESS_XML_FILE = File.join(ASSETS_DIR, 'address_book.xml')
17
+ ENCODING_HTML_FILE = File.join(ASSETS_DIR, 'encoding.html')
18
+ ENCODING_XHTML_FILE = File.join(ASSETS_DIR, 'encoding.xhtml')
19
+ EXML_FILE = File.join(ASSETS_DIR, 'exslt.xml')
20
+ EXSLT_FILE = File.join(ASSETS_DIR, 'exslt.xslt')
21
+ HTML_FILE = File.join(ASSETS_DIR, 'tlm.html')
22
+ METACHARSET_FILE = File.join(ASSETS_DIR, 'metacharset.html')
23
+ NICH_FILE = File.join(ASSETS_DIR, '2ch.html')
24
+ NOENCODING_FILE = File.join(ASSETS_DIR, 'noencoding.html')
25
+ PO_SCHEMA_FILE = File.join(ASSETS_DIR, 'po.xsd')
26
+ PO_XML_FILE = File.join(ASSETS_DIR, 'po.xml')
27
+ SHIFT_JIS_HTML = File.join(ASSETS_DIR, 'shift_jis.html')
28
+ SHIFT_JIS_XML = File.join(ASSETS_DIR, 'shift_jis.xml')
29
+ SNUGGLES_FILE = File.join(ASSETS_DIR, 'snuggles.xml')
30
+ XML_FILE = File.join(ASSETS_DIR, 'staff.xml')
31
+ XML_XINCLUDE_FILE = File.join(ASSETS_DIR, 'xinclude.xml')
32
+ XSLT_FILE = File.join(ASSETS_DIR, 'staff.xslt')
33
33
 
34
34
  def teardown
35
35
  if ENV['NOKOGIRI_GC']
@@ -68,33 +68,6 @@ module Nokogiri
68
68
  alias :assert_not_nil :refute_nil
69
69
  alias :assert_raise :assert_raises
70
70
  alias :assert_not_equal :refute_equal
71
-
72
- def assert_nothing_raised(*args)
73
- self._assertions += 1
74
- if Module === args.last
75
- msg = nil
76
- else
77
- msg = args.pop
78
- end
79
- begin
80
- line = __LINE__; yield
81
- rescue Exception => e
82
- bt = e.backtrace
83
- as = e.instance_of?(MiniTest::Assertion)
84
- if as
85
- ans = /\A#{Regexp.quote(__FILE__)}:#{line}:in /o
86
- bt.reject! {|ln| ans =~ ln}
87
- end
88
- if ((args.empty? && !as) ||
89
- args.any? {|a| a.instance_of?(Module) ? e.is_a?(a) : e.class == a })
90
- msg = message(msg) { "Exception raised:\n<#{mu_pp(e)}>" }
91
- raise MiniTest::Assertion, msg.call, bt
92
- else
93
- raise
94
- end
95
- end
96
- nil
97
- end
98
71
  end
99
72
 
100
73
  module SAX
@@ -12,19 +12,21 @@ module Nokogiri
12
12
 
13
13
  def test_parse_empty_document
14
14
  # This caused a segfault in libxml 2.6.x
15
- assert_nothing_raised { @parser.parse '' }
15
+ assert_nil @parser.parse ''
16
16
  end
17
17
 
18
18
  def test_parse_empty_file
19
19
  # Make sure empty files don't break stuff
20
20
  empty_file_name = File.join(Dir.tmpdir, 'bogus.xml')
21
21
  FileUtils.touch empty_file_name
22
- assert_nothing_raised { @parser.parse_file empty_file_name }
22
+ # assert_nothing_raised do
23
+ @parser.parse_file empty_file_name
24
+ # end
23
25
  end
24
26
 
25
27
  def test_parse_file
26
28
  @parser.parse_file(HTML_FILE)
27
-
29
+
28
30
  # Take a look at the comment in test_parse_document to know
29
31
  # a possible reason to this difference.
30
32
  if Nokogiri.uses_libxml?
@@ -7,15 +7,13 @@ module Nokogiri
7
7
  module SAX
8
8
  class TestParserContext < Nokogiri::SAX::TestCase
9
9
  def test_from_io
10
- assert_nothing_raised do
11
- ParserContext.new StringIO.new('fo'), 'UTF-8'
12
- end
10
+ ctx = ParserContext.new StringIO.new('fo'), 'UTF-8'
11
+ assert ctx
13
12
  end
14
13
 
15
14
  def test_from_string
16
- assert_nothing_raised do
17
- ParserContext.new 'blah blah'
18
- end
15
+ ctx = ParserContext.new 'blah blah'
16
+ assert ctx
19
17
  end
20
18
 
21
19
  def test_parse_with
@@ -26,20 +24,20 @@ module Nokogiri
26
24
  end
27
25
 
28
26
  def test_parse_with_sax_parser
29
- assert_nothing_raised do
27
+ # assert_nothing_raised do
30
28
  xml = "<root />"
31
29
  ctx = ParserContext.new xml
32
30
  parser = Parser.new Doc.new
33
31
  ctx.parse_with parser
34
- end
32
+ # end
35
33
  end
36
34
 
37
35
  def test_from_file
38
- assert_nothing_raised do
36
+ # assert_nothing_raised do
39
37
  ctx = ParserContext.file HTML_FILE, 'UTF-8'
40
38
  parser = Parser.new Doc.new
41
39
  ctx.parse_with parser
42
- end
40
+ # end
43
41
  end
44
42
  end
45
43
  end
@@ -125,8 +125,10 @@ module Nokogiri
125
125
 
126
126
  def test_meta_encoding
127
127
  assert_equal 'UTF-8', @html.meta_encoding
128
+ end
128
129
 
129
- html = Nokogiri::HTML(<<-eohtml)
130
+ def test_meta_encoding_is_strict_about_http_equiv
131
+ doc = Nokogiri::HTML(<<-eohtml)
130
132
  <html>
131
133
  <head>
132
134
  <meta http-equiv="X-Content-Type" content="text/html; charset=Shift_JIS">
@@ -136,7 +138,21 @@ module Nokogiri
136
138
  </body>
137
139
  </html>
138
140
  eohtml
139
- assert_nil html.meta_encoding
141
+ assert_nil doc.meta_encoding
142
+ end
143
+
144
+ def test_meta_encoding_handles_malformed_content_charset
145
+ doc = Nokogiri::HTML(<<EOHTML)
146
+ <html>
147
+ <head>
148
+ <meta http-equiv="Content-type" content="text/html; utf-8" />
149
+ </head>
150
+ <body>
151
+ foo
152
+ </body>
153
+ </html>
154
+ EOHTML
155
+ assert_nil doc.meta_encoding
140
156
  end
141
157
 
142
158
  def test_meta_encoding=
@@ -232,9 +248,7 @@ eohtml
232
248
  end
233
249
 
234
250
  def test_parse_handles_nil_gracefully
235
- assert_nothing_raised do
236
- @doc = Nokogiri::HTML::Document.parse(nil)
237
- end
251
+ @doc = Nokogiri::HTML::Document.parse(nil)
238
252
  assert_instance_of Nokogiri::HTML::Document, @doc
239
253
  end
240
254
 
@@ -101,9 +101,7 @@ module Nokogiri
101
101
  assert another_node, 'should have a node'
102
102
 
103
103
  # This used to segv
104
- assert_nothing_raised do
105
- node.add_previous_sibling another_node
106
- end
104
+ assert node.add_previous_sibling another_node
107
105
  end
108
106
 
109
107
  def test_swap
@@ -138,7 +136,7 @@ module Nokogiri
138
136
 
139
137
  def test_fragment_handler_does_not_regurge_on_invalid_attributes
140
138
  iframe = %Q{<iframe style="width: 0%; height: 0px" src="http://someurl" allowtransparency></iframe>}
141
- assert_nothing_raised { @html.at('div').fragment(iframe) }
139
+ assert @html.at('div').fragment(iframe)
142
140
  end
143
141
 
144
142
  def test_fragment
@@ -422,4 +422,67 @@ class TestReader < Nokogiri::TestCase
422
422
  end
423
423
  end
424
424
 
425
+ def test_correct_outer_xml_inclusion
426
+ xml = Nokogiri::XML::Reader.from_io(StringIO.new(<<-eoxml))
427
+ <root-element>
428
+ <children>
429
+ <child n="1">
430
+ <field>child-1</field>
431
+ </child>
432
+ <child n="2">
433
+ <field>child-2</field>
434
+ </child>
435
+ <child n="3">
436
+ <field>child-3</field>
437
+ </child>
438
+ </children>
439
+ </root-element>
440
+ eoxml
441
+
442
+ nodelengths = []
443
+ has_child2 = []
444
+
445
+ xml.each do |node|
446
+ if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT and node.name == "child"
447
+ nodelengths << node.outer_xml.length
448
+ has_child2 << !!(node.outer_xml =~ /child-2/)
449
+ end
450
+ end
451
+
452
+ assert_equal(nodelengths[0], nodelengths[1])
453
+ assert(has_child2[1])
454
+ assert(!has_child2[0])
455
+ end
456
+
457
+ def test_correct_inner_xml_inclusion
458
+ xml = Nokogiri::XML::Reader.from_io(StringIO.new(<<-eoxml))
459
+ <root-element>
460
+ <children>
461
+ <child n="1">
462
+ <field>child-1</field>
463
+ </child>
464
+ <child n="2">
465
+ <field>child-2</field>
466
+ </child>
467
+ <child n="3">
468
+ <field>child-3</field>
469
+ </child>
470
+ </children>
471
+ </root-element>
472
+ eoxml
473
+
474
+ nodelengths = []
475
+ has_child2 = []
476
+
477
+ xml.each do |node|
478
+ if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT and node.name == "child"
479
+ nodelengths << node.inner_xml.length
480
+ has_child2 << !!(node.inner_xml =~ /child-2/)
481
+ end
482
+ end
483
+
484
+ assert_equal(nodelengths[0], nodelengths[1])
485
+ assert(has_child2[1])
486
+ assert(!has_child2[0])
487
+ end
425
488
  end