nokogiri 1.6.8.rc3-java → 1.6.8.1-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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -3
  3. data/CHANGELOG.rdoc +41 -5
  4. data/CONTRIBUTING.md +1 -1
  5. data/Gemfile +7 -8
  6. data/Manifest.txt +1 -1
  7. data/README.md +0 -3
  8. data/Rakefile +10 -12
  9. data/build_all +1 -1
  10. data/dependencies.yml +29 -4
  11. data/ext/java/nokogiri/XmlAttr.java +3 -1
  12. data/ext/java/nokogiri/XmlDocumentFragment.java +0 -14
  13. data/ext/java/nokogiri/XmlNode.java +74 -58
  14. data/ext/java/nokogiri/internals/NokogiriHelpers.java +7 -7
  15. data/ext/java/nokogiri/internals/SaveContextVisitor.java +5 -1
  16. data/ext/nokogiri/extconf.rb +89 -33
  17. data/ext/nokogiri/xml_node.c +22 -9
  18. data/ext/nokogiri/xml_reader.c +0 -13
  19. data/ext/nokogiri/xml_sax_parser.c +7 -7
  20. data/lib/nokogiri.rb +11 -7
  21. data/lib/nokogiri/html/document.rb +4 -2
  22. data/lib/nokogiri/nokogiri.jar +0 -0
  23. data/lib/nokogiri/version.rb +1 -1
  24. data/lib/nokogiri/xml/document.rb +1 -1
  25. data/lib/nokogiri/xml/parse_options.rb +22 -0
  26. data/tasks/test.rb +5 -0
  27. data/test/html/test_document.rb +26 -0
  28. data/test/html/test_document_encoding.rb +5 -0
  29. data/test/html/test_document_fragment.rb +5 -0
  30. data/test/test_encoding_handler.rb +2 -0
  31. data/test/test_xslt_transforms.rb +33 -0
  32. data/test/xml/sax/test_parser.rb +15 -7
  33. data/test/xml/test_document_encoding.rb +5 -0
  34. data/test/xml/test_document_fragment.rb +12 -0
  35. data/test/xml/test_node_attributes.rb +6 -0
  36. data/test/xml/test_node_reparenting.rb +193 -18
  37. data/test/xml/test_reader.rb +589 -0
  38. data/test/xml/test_unparented_node.rb +13 -0
  39. data/test_all +33 -42
  40. metadata +63 -66
  41. data/test/test_reader.rb +0 -577
@@ -422,6 +422,19 @@ module Nokogiri
422
422
  old_node = @node.at('.//employee')
423
423
  assert_raises(ArgumentError){ old_node.replace new_node }
424
424
  end
425
+
426
+ def test_unlink_on_unlinked_node_1
427
+ node = Nokogiri::XML::Node.new 'div', Nokogiri::XML::Document.new
428
+ node.unlink # must_not_raise
429
+ assert_nil node.parent
430
+ end
431
+
432
+ def test_unlink_on_unlinked_node_2
433
+ node = Nokogiri::XML('<div>foo</div>').at_css("div")
434
+ node.unlink
435
+ node.unlink # must_not_raise
436
+ assert_nil node.parent
437
+ end
425
438
  end
426
439
  end
427
440
  end
data/test_all CHANGED
@@ -25,13 +25,12 @@ RUBIES="\
25
25
  TEST_LOG=test.log
26
26
  VALGRIND_LOG=valgrind.log
27
27
 
28
- if ! grep libxml-ruby Gemfile ; then
29
- echo "ERROR: please add this line your Gemfile temporarily so we can run libxml-ruby tests:"
30
- echo
31
- echo "gem 'libxml-ruby', :platform => :mri"
32
- echo
33
- exit 1
34
- fi
28
+ # make sure we can test with libxml-ruby installed
29
+ export BUNDLE_GEMFILE="$(pwd)/Gemfile_test_all"
30
+ cat > $BUNDLE_GEMFILE <<EOF
31
+ gem "libxml-ruby", :platform => :mri, :require => false
32
+ eval_gemfile File.join(File.dirname(ENV['BUNDLE_GEMFILE']),"Gemfile")
33
+ EOF
35
34
 
36
35
  # Load RVM into a shell session *as a function*
37
36
  if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
@@ -51,20 +50,12 @@ function rvm_use {
51
50
  rvm use "${1}@nokogiri" --create
52
51
  }
53
52
 
54
- function generate_parser_and_tokenizer {
55
- old_ruby=$current_ruby
56
- rvm_use ruby-1.9.3
57
- bundle exec rake generate 2>&1 > /dev/null
58
- rvm_use $old_ruby
59
- }
60
-
61
53
  function clean {
62
54
  bundle exec rake clean clobber 2>&1 > /dev/null
63
55
  }
64
56
 
65
57
  function compile {
66
58
  echo "** compiling ..."
67
- # generate_parser_and_tokenizer
68
59
  bundle exec rake compile 2>&1 > /dev/null
69
60
  }
70
61
 
@@ -75,9 +66,9 @@ done
75
66
 
76
67
  for ruby in $RUBIES ; do
77
68
  rvm_use ${ruby}
78
- if ! [[ $(bundle -v) =~ "1.10." ]] ; then
69
+ if ! [[ $(bundle -v) =~ "1.12." ]] ; then
79
70
  yes | gem uninstall --force bundler
80
- gem install bundler -v 1.10.6
71
+ gem install bundler -v 1.12.5
81
72
  bundle -v
82
73
  fi
83
74
  bundle install --quiet --local || bundle install
@@ -85,32 +76,32 @@ for ruby in $RUBIES ; do
85
76
  done
86
77
 
87
78
  for ruby in $RUBIES ; do
79
+ rvm_use ${ruby}
80
+ echo -e "**\n** testing nokogiri on ${ruby}\n**"
81
+ clean
82
+ compile
83
+ echo "** running tests ..."
84
+ bundle exec rake test 2>&1
85
+ if [[ ! $ruby =~ "jruby" ]] ; then
86
+ echo "** running tests again with libxml-ruby loaded ..."
87
+ if ! gem list libxml-ruby | fgrep 2.8.0 ; then
88
+ gem install libxml-ruby
89
+ fi
90
+ bundle exec rake test:libxml-ruby 2>&1
91
+ fi
92
+ clean
93
+ done | tee -a $TEST_LOG
94
+
95
+ for ruby in $RUBIES ; do
96
+ if [[ ! $ruby =~ "jruby" ]] ; then
88
97
  rvm_use ${ruby}
89
- echo -e "**\n** testing nokogiri on ${ruby}\n**" | tee -a $TEST_LOG
98
+ echo -e "**\n** nokogiri prerelease: ${ruby}\n**"
90
99
  clean
91
100
  compile
92
- echo "** running tests ..."
93
- bundle exec rake test 2>&1 | tee -a $TEST_LOG
94
- if [[ ! $ruby =~ "jruby" ]] ; then
95
- echo "** running tests again with libxml-ruby loaded ..."
96
- if ! gem list libxml-ruby | fgrep 2.8.0 ; then
97
- gem install libxml-ruby
98
- fi
99
- bundle exec rake test:libxml-ruby 2>&1 | tee -a $TEST_LOG
100
- fi
101
+ echo "** running valgrind on tests ..."
102
+ bundle exec rake test:valgrind 2>&1
103
+ echo "** running valgrind again with libxml-ruby loaded ..."
104
+ bundle exec rake test:valgrind:libxml-ruby 2>&1
101
105
  clean
102
- done
103
-
104
- for ruby in $RUBIES ; do
105
- if [[ ! $ruby =~ "jruby" ]] ; then
106
- rvm_use ${ruby}
107
- echo -e "**\n** nokogiri prerelease: ${ruby}\n**" | tee -a $VALGRIND_LOG
108
- clean
109
- compile
110
- echo "** running valgrind on tests ..."
111
- bundle exec rake test:valgrind 2>&1 | tee -a $VALGRIND_LOG
112
- echo "** running valgrind again with libxml-ruby loaded ..."
113
- bundle exec rake test:valgrind:libxml-ruby 2>&1 | tee -a $VALGRIND_LOG
114
- clean
115
- fi
116
- done
106
+ fi
107
+ done | tee -a $VALGRIND_LOG
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.8.rc3
4
+ version: 1.6.8.1
5
5
  platform: java
6
6
  authors:
7
7
  - Aaron Patterson
@@ -12,183 +12,180 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2016-02-17 00:00:00.000000000 Z
15
+ date: 2016-10-03 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
- name: rdoc
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ~>
22
- - !ruby/object:Gem::Version
23
- version: '4.0'
24
18
  requirement: !ruby/object:Gem::Requirement
25
19
  requirements:
26
20
  - - ~>
27
21
  - !ruby/object:Gem::Version
28
22
  version: '4.0'
23
+ name: rdoc
29
24
  prerelease: false
30
25
  type: :development
31
- - !ruby/object:Gem::Dependency
32
- name: hoe-bundler
33
26
  version_requirements: !ruby/object:Gem::Requirement
34
27
  requirements:
35
- - - '>='
28
+ - - ~>
36
29
  - !ruby/object:Gem::Version
37
- version: '1.1'
30
+ version: '4.0'
31
+ - !ruby/object:Gem::Dependency
38
32
  requirement: !ruby/object:Gem::Requirement
39
33
  requirements:
40
- - - '>='
34
+ - - ~>
41
35
  - !ruby/object:Gem::Version
42
- version: '1.1'
36
+ version: 1.2.0
37
+ name: hoe-bundler
43
38
  prerelease: false
44
39
  type: :development
45
- - !ruby/object:Gem::Dependency
46
- name: hoe-debugging
47
40
  version_requirements: !ruby/object:Gem::Requirement
48
41
  requirements:
49
42
  - - ~>
50
43
  - !ruby/object:Gem::Version
51
- version: 1.2.1
44
+ version: 1.2.0
45
+ - !ruby/object:Gem::Dependency
52
46
  requirement: !ruby/object:Gem::Requirement
53
47
  requirements:
54
48
  - - ~>
55
49
  - !ruby/object:Gem::Version
56
50
  version: 1.2.1
51
+ name: hoe-debugging
57
52
  prerelease: false
58
53
  type: :development
59
- - !ruby/object:Gem::Dependency
60
- name: hoe-gemspec
61
54
  version_requirements: !ruby/object:Gem::Requirement
62
55
  requirements:
63
- - - '>='
56
+ - - ~>
64
57
  - !ruby/object:Gem::Version
65
- version: '1.0'
58
+ version: 1.2.1
59
+ - !ruby/object:Gem::Dependency
66
60
  requirement: !ruby/object:Gem::Requirement
67
61
  requirements:
68
- - - '>='
62
+ - - ~>
69
63
  - !ruby/object:Gem::Version
70
- version: '1.0'
64
+ version: 1.0.0
65
+ name: hoe-gemspec
71
66
  prerelease: false
72
67
  type: :development
73
- - !ruby/object:Gem::Dependency
74
- name: hoe-git
75
68
  version_requirements: !ruby/object:Gem::Requirement
76
69
  requirements:
77
- - - '>='
70
+ - - ~>
78
71
  - !ruby/object:Gem::Version
79
- version: '1.4'
72
+ version: 1.0.0
73
+ - !ruby/object:Gem::Dependency
80
74
  requirement: !ruby/object:Gem::Requirement
81
75
  requirements:
82
- - - '>='
76
+ - - ~>
83
77
  - !ruby/object:Gem::Version
84
- version: '1.4'
78
+ version: 1.6.0
79
+ name: hoe-git
85
80
  prerelease: false
86
81
  type: :development
87
- - !ruby/object:Gem::Dependency
88
- name: minitest
89
82
  version_requirements: !ruby/object:Gem::Requirement
90
83
  requirements:
91
84
  - - ~>
92
85
  - !ruby/object:Gem::Version
93
- version: 2.2.2
86
+ version: 1.6.0
87
+ - !ruby/object:Gem::Dependency
94
88
  requirement: !ruby/object:Gem::Requirement
95
89
  requirements:
96
90
  - - ~>
97
91
  - !ruby/object:Gem::Version
98
- version: 2.2.2
92
+ version: 5.8.4
93
+ name: minitest
99
94
  prerelease: false
100
95
  type: :development
101
- - !ruby/object:Gem::Dependency
102
- name: rake
103
96
  version_requirements: !ruby/object:Gem::Requirement
104
97
  requirements:
105
- - - '>='
98
+ - - ~>
106
99
  - !ruby/object:Gem::Version
107
- version: '0.9'
100
+ version: 5.8.4
101
+ - !ruby/object:Gem::Dependency
108
102
  requirement: !ruby/object:Gem::Requirement
109
103
  requirements:
110
- - - '>='
104
+ - - ~>
111
105
  - !ruby/object:Gem::Version
112
- version: '0.9'
106
+ version: 10.5.0
107
+ name: rake
113
108
  prerelease: false
114
109
  type: :development
115
- - !ruby/object:Gem::Dependency
116
- name: rake-compiler
117
110
  version_requirements: !ruby/object:Gem::Requirement
118
111
  requirements:
119
112
  - - ~>
120
113
  - !ruby/object:Gem::Version
121
- version: 0.9.2
114
+ version: 10.5.0
115
+ - !ruby/object:Gem::Dependency
122
116
  requirement: !ruby/object:Gem::Requirement
123
117
  requirements:
124
118
  - - ~>
125
119
  - !ruby/object:Gem::Version
126
120
  version: 0.9.2
121
+ name: rake-compiler
127
122
  prerelease: false
128
123
  type: :development
129
- - !ruby/object:Gem::Dependency
130
- name: rake-compiler-dock
131
124
  version_requirements: !ruby/object:Gem::Requirement
132
125
  requirements:
133
126
  - - ~>
134
127
  - !ruby/object:Gem::Version
135
- version: 0.5.1
128
+ version: 0.9.2
129
+ - !ruby/object:Gem::Dependency
136
130
  requirement: !ruby/object:Gem::Requirement
137
131
  requirements:
138
132
  - - ~>
139
133
  - !ruby/object:Gem::Version
140
134
  version: 0.5.1
135
+ name: rake-compiler-dock
141
136
  prerelease: false
142
137
  type: :development
143
- - !ruby/object:Gem::Dependency
144
- name: racc
145
138
  version_requirements: !ruby/object:Gem::Requirement
146
139
  requirements:
147
- - - '>='
140
+ - - ~>
148
141
  - !ruby/object:Gem::Version
149
- version: 1.4.6
142
+ version: 0.5.1
143
+ - !ruby/object:Gem::Dependency
150
144
  requirement: !ruby/object:Gem::Requirement
151
145
  requirements:
152
- - - '>='
146
+ - - ~>
153
147
  - !ruby/object:Gem::Version
154
- version: 1.4.6
148
+ version: 1.4.14
149
+ name: racc
155
150
  prerelease: false
156
151
  type: :development
157
- - !ruby/object:Gem::Dependency
158
- name: rexical
159
152
  version_requirements: !ruby/object:Gem::Requirement
160
153
  requirements:
161
- - - '>='
154
+ - - ~>
162
155
  - !ruby/object:Gem::Version
163
- version: 1.0.5
156
+ version: 1.4.14
157
+ - !ruby/object:Gem::Dependency
164
158
  requirement: !ruby/object:Gem::Requirement
165
159
  requirements:
166
- - - '>='
160
+ - - ~>
167
161
  - !ruby/object:Gem::Version
168
162
  version: 1.0.5
163
+ name: rexical
169
164
  prerelease: false
170
165
  type: :development
171
- - !ruby/object:Gem::Dependency
172
- name: hoe
173
166
  version_requirements: !ruby/object:Gem::Requirement
174
167
  requirements:
175
168
  - - ~>
176
169
  - !ruby/object:Gem::Version
177
- version: '3.14'
170
+ version: 1.0.5
171
+ - !ruby/object:Gem::Dependency
178
172
  requirement: !ruby/object:Gem::Requirement
179
173
  requirements:
180
174
  - - ~>
181
175
  - !ruby/object:Gem::Version
182
- version: '3.14'
176
+ version: '3.15'
177
+ name: hoe
183
178
  prerelease: false
184
179
  type: :development
180
+ version_requirements: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ~>
183
+ - !ruby/object:Gem::Version
184
+ version: '3.15'
185
185
  description: |-
186
186
  Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser. Among
187
187
  Nokogiri's many features is the ability to search documents via XPath
188
188
  or CSS3 selectors.
189
-
190
- XML is like violence - if it doesn’t solve your problems, you are not
191
- using enough of it.
192
189
  email:
193
190
  - aaronp@rubyforge.org
194
191
  - mike.dalessio@gmail.com
@@ -566,7 +563,6 @@ files:
566
563
  - test/test_encoding_handler.rb
567
564
  - test/test_memory_leak.rb
568
565
  - test/test_nokogiri.rb
569
- - test/test_reader.rb
570
566
  - test/test_soap4r_sax.rb
571
567
  - test/test_xslt_transforms.rb
572
568
  - test/xml/node/test_save_options.rb
@@ -598,6 +594,7 @@ files:
598
594
  - test/xml/test_node_set.rb
599
595
  - test/xml/test_parse_options.rb
600
596
  - test/xml/test_processing_instruction.rb
597
+ - test/xml/test_reader.rb
601
598
  - test/xml/test_reader_encoding.rb
602
599
  - test/xml/test_relax_ng.rb
603
600
  - test/xml/test_schema.rb
@@ -626,9 +623,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
626
623
  version: '0'
627
624
  required_rubygems_version: !ruby/object:Gem::Requirement
628
625
  requirements:
629
- - - '>'
626
+ - - '>='
630
627
  - !ruby/object:Gem::Version
631
- version: 1.3.1
628
+ version: '0'
632
629
  requirements: []
633
630
  rubyforge_project:
634
631
  rubygems_version: 2.4.5
@@ -1,577 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require "helper"
3
-
4
- class TestReader < Nokogiri::TestCase
5
- def test_from_io_sets_io_as_source
6
- io = File.open SNUGGLES_FILE
7
- reader = Nokogiri::XML::Reader.from_io(io)
8
- assert_equal io, reader.source
9
- end
10
-
11
- def test_empty_element?
12
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
13
- <xml><city>Paris</city><state/></xml>
14
- eoxml
15
-
16
- results = reader.map do |node|
17
- if node.node_type == Nokogiri::XML::Node::ELEMENT_NODE
18
- node.empty_element?
19
- end
20
- end
21
- assert_equal [false, false, nil, nil, true, nil], results
22
- end
23
-
24
- def test_self_closing?
25
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
26
- <xml><city>Paris</city><state/></xml>
27
- eoxml
28
-
29
- results = reader.map do |node|
30
- if node.node_type == Nokogiri::XML::Node::ELEMENT_NODE
31
- node.self_closing?
32
- end
33
- end
34
- assert_equal [false, false, nil, nil, true, nil], results
35
- end
36
-
37
- # Issue #831
38
- # Make sure that the reader doesn't block reading the entire input
39
- def test_reader_blocking
40
- rd, wr = IO.pipe()
41
- node_out = nil
42
- t = Thread.start do
43
- reader = Nokogiri::XML::Reader(rd, 'UTF-8')
44
- reader.each do |node|
45
- node_out = node
46
- break
47
- end
48
- rd.close
49
- end
50
- sleep(1) # sleep for one second to make sure the reader will actually block for input
51
- begin
52
- wr.puts "<foo>"
53
- wr.puts "<bar/>" * 10000
54
- wr.flush
55
- rescue Errno::EPIPE
56
- end
57
- res = t.join(5) # wait 5 seconds for the thread to finish
58
- wr.close
59
- refute_nil node_out, "Didn't read any nodes, exclude the trivial case"
60
- refute_nil res, "Reader blocks trying to read the entire stream"
61
- end
62
-
63
- def test_reader_takes_block
64
- options = nil
65
- Nokogiri::XML::Reader(File.read(XML_FILE), XML_FILE) do |cfg|
66
- options = cfg
67
- options.nonet.nowarning.dtdattr
68
- end
69
- assert options.nonet?
70
- assert options.nowarning?
71
- assert options.dtdattr?
72
- end
73
-
74
- def test_nil_raises
75
- assert_raises(ArgumentError) {
76
- Nokogiri::XML::Reader.from_memory(nil)
77
- }
78
- assert_raises(ArgumentError) {
79
- Nokogiri::XML::Reader.from_io(nil)
80
- }
81
- end
82
-
83
- def test_from_io
84
- io = File.open SNUGGLES_FILE
85
- reader = Nokogiri::XML::Reader.from_io(io)
86
- assert_equal false, reader.default?
87
- assert_equal [false, false, false, false, false, false, false],
88
- reader.map(&:default?)
89
- end
90
-
91
- def test_io
92
- io = File.open SNUGGLES_FILE
93
- reader = Nokogiri::XML::Reader(io)
94
- assert_equal false, reader.default?
95
- assert_equal [false, false, false, false, false, false, false],
96
- reader.map(&:default?)
97
- end
98
-
99
- def test_string_io
100
- io = StringIO.new(<<-eoxml)
101
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
102
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
103
- </x>
104
- eoxml
105
- reader = Nokogiri::XML::Reader(io)
106
- assert_equal false, reader.default?
107
- assert_equal [false, false, false, false, false, false, false],
108
- reader.map(&:default?)
109
- end
110
-
111
- class ReallyBadIO
112
- def read(size)
113
- 'a' * size ** 10
114
- end
115
- end
116
-
117
- class ReallyBadIO4Java
118
- def read(size=1)
119
- 'a' * size ** 10
120
- end
121
- end
122
-
123
- def test_io_that_reads_too_much
124
- if Nokogiri.jruby?
125
- io = ReallyBadIO4Java.new
126
- Nokogiri::XML::Reader(io)
127
- else
128
- io = ReallyBadIO.new
129
- Nokogiri::XML::Reader(io)
130
- end
131
- end
132
-
133
- def test_in_memory
134
- assert Nokogiri::XML::Reader(<<-eoxml)
135
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
136
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
137
- </x>
138
- eoxml
139
- end
140
-
141
- def test_reader_holds_on_to_string
142
- xml = <<-eoxml
143
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
144
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
145
- </x>
146
- eoxml
147
- reader = Nokogiri::XML::Reader(xml)
148
- assert_equal xml, reader.source
149
- end
150
-
151
- def test_default?
152
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
153
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
154
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
155
- </x>
156
- eoxml
157
- assert_equal false, reader.default?
158
- assert_equal [false, false, false, false, false, false, false],
159
- reader.map(&:default?)
160
- end
161
-
162
- def test_value?
163
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
164
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
165
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
166
- </x>
167
- eoxml
168
- assert_equal false, reader.value?
169
- assert_equal [false, true, false, true, false, true, false],
170
- reader.map(&:value?)
171
- end
172
-
173
- def test_read_error_document
174
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
175
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
176
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
177
- <foo>
178
- </x>
179
- eoxml
180
- assert_raises(Nokogiri::XML::SyntaxError) do
181
- reader.each { |node| }
182
- end
183
- assert 1, reader.errors.length
184
- end
185
-
186
- def test_attributes?
187
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
188
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
189
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
190
- </x>
191
- eoxml
192
- assert_equal false, reader.attributes?
193
- assert_equal [true, false, true, false, true, false, true],
194
- reader.map(&:attributes?)
195
- end
196
-
197
- def test_attributes
198
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
199
- <x xmlns:tenderlove='http://tenderlovemaking.com/'
200
- xmlns='http://mothership.connection.com/'
201
- >
202
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
203
- </x>
204
- eoxml
205
- assert_equal({}, reader.attributes)
206
- assert_equal [{'xmlns:tenderlove'=>'http://tenderlovemaking.com/',
207
- 'xmlns'=>'http://mothership.connection.com/'},
208
- {}, {"awesome"=>"true"}, {}, {"awesome"=>"true"}, {},
209
- {'xmlns:tenderlove'=>'http://tenderlovemaking.com/',
210
- 'xmlns'=>'http://mothership.connection.com/'}],
211
- reader.map(&:attributes)
212
- end
213
-
214
- def test_attribute_roundtrip
215
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
216
- <x xmlns:tenderlove='http://tenderlovemaking.com/'
217
- xmlns='http://mothership.connection.com/'
218
- >
219
- <tenderlove:foo awesome='true' size='giant'>snuggles!</tenderlove:foo>
220
- </x>
221
- eoxml
222
- reader.each do |node|
223
- node.attributes.each do |key, value|
224
- assert_equal value, node.attribute(key)
225
- end
226
- end
227
- end
228
-
229
- def test_attribute_at
230
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
231
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
232
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
233
- </x>
234
- eoxml
235
- assert_nil reader.attribute_at(nil)
236
- assert_nil reader.attribute_at(0)
237
- assert_equal ['http://tenderlovemaking.com/', nil, 'true', nil, 'true', nil, 'http://tenderlovemaking.com/'],
238
- reader.map { |x| x.attribute_at(0) }
239
- end
240
-
241
- def test_attribute
242
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
243
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
244
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
245
- </x>
246
- eoxml
247
- assert_nil reader.attribute(nil)
248
- assert_nil reader.attribute('awesome')
249
- assert_equal [nil, nil, 'true', nil, 'true', nil, nil],
250
- reader.map { |x| x.attribute('awesome') }
251
- end
252
-
253
- def test_attribute_length
254
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
255
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
256
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
257
- </x>
258
- eoxml
259
- assert_equal 0, reader.attribute_count
260
- assert_equal [1, 0, 1, 0, 0, 0, 0], reader.map(&:attribute_count)
261
- end
262
-
263
- def test_depth
264
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
265
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
266
- <tenderlove:foo>snuggles!</tenderlove:foo>
267
- </x>
268
- eoxml
269
- assert_equal 0, reader.depth
270
- assert_equal [0, 1, 1, 2, 1, 1, 0], reader.map(&:depth)
271
- end
272
-
273
- def test_encoding
274
- string = <<-eoxml
275
- <awesome>
276
- <p xml:lang="en">The quick brown fox jumps over the lazy dog.</p>
277
- <p xml:lang="ja">日本語が上手です</p>
278
- </awesome>
279
- eoxml
280
- reader = Nokogiri::XML::Reader.from_memory(string, nil, 'UTF-8')
281
- assert_equal ['UTF-8'], reader.map(&:encoding).uniq
282
- end
283
-
284
- def test_xml_version
285
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
286
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
287
- <tenderlove:foo>snuggles!</tenderlove:foo>
288
- </x>
289
- eoxml
290
- assert_nil reader.xml_version
291
- assert_equal ['1.0'], reader.map(&:xml_version).uniq
292
- end
293
-
294
- def test_lang
295
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
296
- <awesome>
297
- <p xml:lang="en">The quick brown fox jumps over the lazy dog.</p>
298
- <p xml:lang="ja">日本語が上手です</p>
299
- </awesome>
300
- eoxml
301
- assert_nil reader.lang
302
- assert_equal [nil, nil, "en", "en", "en", nil, "ja", "ja", "ja", nil, nil],
303
- reader.map(&:lang)
304
- end
305
-
306
- def test_value
307
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
308
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
309
- <tenderlove:foo>snuggles!</tenderlove:foo>
310
- </x>
311
- eoxml
312
- assert_nil reader.value
313
- assert_equal [nil, "\n ", nil, "snuggles!", nil, "\n ", nil],
314
- reader.map(&:value)
315
- end
316
-
317
- def test_prefix
318
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
319
- <x xmlns:edi='http://ecommerce.example.org/schema'>
320
- <edi:foo>hello</edi:foo>
321
- </x>
322
- eoxml
323
- assert_nil reader.prefix
324
- assert_equal [nil, nil, "edi", nil, "edi", nil, nil],
325
- reader.map(&:prefix)
326
- end
327
-
328
- def test_node_type
329
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
330
- <x>
331
- <y>hello</y>
332
- </x>
333
- eoxml
334
- assert_equal 0, reader.node_type
335
- assert_equal [1, 14, 1, 3, 15, 14, 15], reader.map(&:node_type)
336
- end
337
-
338
- def test_inner_xml
339
- str = "<x><y>hello</y></x>"
340
- reader = Nokogiri::XML::Reader.from_memory(str)
341
-
342
- reader.read
343
-
344
- assert_equal "<y>hello</y>", reader.inner_xml
345
- end
346
-
347
- def test_outer_xml
348
- str = ["<x><y>hello</y></x>", "<y>hello</y>", "hello", "<y/>", "<x/>"]
349
- reader = Nokogiri::XML::Reader.from_memory(str.first)
350
-
351
- xml = []
352
- reader.map { |node| xml << node.outer_xml }
353
-
354
- assert_equal str, xml
355
- end
356
-
357
- def test_outer_xml_with_empty_nodes
358
- str = ["<x><y/></x>", "<y/>", "<x/>"]
359
- reader = Nokogiri::XML::Reader.from_memory(str.first)
360
-
361
- xml = []
362
- reader.map { |node| xml << node.outer_xml }
363
-
364
- assert_equal str, xml
365
- end
366
-
367
- def test_state
368
- reader = Nokogiri::XML::Reader.from_memory('<foo>bar</bar>')
369
- assert reader.state
370
- end
371
-
372
- def test_ns_uri
373
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
374
- <x xmlns:edi='http://ecommerce.example.org/schema'>
375
- <edi:foo>hello</edi:foo>
376
- </x>
377
- eoxml
378
- assert_nil reader.namespace_uri
379
- assert_equal([nil,
380
- nil,
381
- "http://ecommerce.example.org/schema",
382
- nil,
383
- "http://ecommerce.example.org/schema",
384
- nil,
385
- nil],
386
- reader.map(&:namespace_uri))
387
- end
388
-
389
- def test_namespaced_attributes
390
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
391
- <x xmlns:edi='http://ecommerce.example.org/schema' xmlns:commons="http://rets.org/xsd/RETSCommons">
392
- <edi:foo commons:street-number="43">hello</edi:foo>
393
- <y edi:name="francis" bacon="87"/>
394
- </x>
395
- eoxml
396
- attr_ns = []
397
- while reader.read
398
- if reader.node_type == Nokogiri::XML::Node::ELEMENT_NODE
399
- reader.attribute_nodes.each {|attr| attr_ns << (attr.namespace.nil? ? nil : attr.namespace.prefix) }
400
- end
401
- end
402
- assert_equal(['commons',
403
- 'edi',
404
- nil],
405
- attr_ns)
406
- end
407
-
408
- def test_local_name
409
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
410
- <x xmlns:edi='http://ecommerce.example.org/schema'>
411
- <edi:foo>hello</edi:foo>
412
- </x>
413
- eoxml
414
- assert_nil reader.local_name
415
- assert_equal(["x", "#text", "foo", "#text", "foo", "#text", "x"],
416
- reader.map(&:local_name))
417
- end
418
-
419
- def test_name
420
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
421
- <x xmlns:edi='http://ecommerce.example.org/schema'>
422
- <edi:foo>hello</edi:foo>
423
- </x>
424
- eoxml
425
- assert_nil reader.name
426
- assert_equal(["x", "#text", "edi:foo", "#text", "edi:foo", "#text", "x"],
427
- reader.map(&:name))
428
- end
429
-
430
- def test_base_uri
431
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
432
- <x xml:base="http://base.example.org/base/">
433
- <link href="link"/>
434
- <other xml:base="http://other.example.org/"/>
435
- <relative xml:base="relative">
436
- <link href="stuff" />
437
- </relative>
438
- </x>
439
- eoxml
440
-
441
- assert_nil reader.base_uri
442
- assert_equal(["http://base.example.org/base/",
443
- "http://base.example.org/base/",
444
- "http://base.example.org/base/",
445
- "http://base.example.org/base/",
446
- "http://other.example.org/",
447
- "http://base.example.org/base/",
448
- "http://base.example.org/base/relative",
449
- "http://base.example.org/base/relative",
450
- "http://base.example.org/base/relative",
451
- "http://base.example.org/base/relative",
452
- "http://base.example.org/base/relative",
453
- "http://base.example.org/base/",
454
- "http://base.example.org/base/"],
455
- reader.map(&:base_uri))
456
- end
457
-
458
- def test_xlink_href_without_base_uri
459
- reader = Nokogiri::XML::Reader(<<-eoxml)
460
- <x xmlns:xlink="http://www.w3.org/1999/xlink">
461
- <link xlink:href="#other">Link</link>
462
- <other id="other">Linked Element</other>
463
- </x>
464
- eoxml
465
-
466
- reader.each do |node|
467
- if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
468
- if node.name == 'link'
469
- assert_nil node.base_uri
470
- end
471
- end
472
- end
473
- end
474
-
475
- def test_xlink_href_with_base_uri
476
- reader = Nokogiri::XML::Reader(<<-eoxml)
477
- <x xml:base="http://base.example.org/base/"
478
- xmlns:xlink="http://www.w3.org/1999/xlink">
479
- <link xlink:href="#other">Link</link>
480
- <other id="other">Linked Element</other>
481
- </x>
482
- eoxml
483
-
484
- reader.each do |node|
485
- if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
486
- assert_equal node.base_uri, "http://base.example.org/base/"
487
- end
488
- end
489
- end
490
-
491
- def test_read_from_memory
492
- called = false
493
- reader = Nokogiri::XML::Reader.from_memory('<foo>bar</foo>')
494
- reader.each do |node|
495
- called = true
496
- assert node
497
- end
498
- assert called
499
- end
500
-
501
- def test_large_document_smoke_test
502
- # simply run on a large document to verify that there no GC issues
503
- xml = []
504
- xml << "<elements>"
505
- 10000.times { |j| xml << "<element id=\"#{j}\"/>" }
506
- xml << "</elements>"
507
- xml = xml.join("\n")
508
-
509
- Nokogiri::XML::Reader.from_memory(xml).each do |e|
510
- e.attributes
511
- end
512
- end
513
-
514
- def test_correct_outer_xml_inclusion
515
- xml = Nokogiri::XML::Reader.from_io(StringIO.new(<<-eoxml))
516
- <root-element>
517
- <children>
518
- <child n="1">
519
- <field>child-1</field>
520
- </child>
521
- <child n="2">
522
- <field>child-2</field>
523
- </child>
524
- <child n="3">
525
- <field>child-3</field>
526
- </child>
527
- </children>
528
- </root-element>
529
- eoxml
530
-
531
- nodelengths = []
532
- has_child2 = []
533
-
534
- xml.each do |node|
535
- if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT and node.name == "child"
536
- nodelengths << node.outer_xml.length
537
- has_child2 << !!(node.outer_xml =~ /child-2/)
538
- end
539
- end
540
-
541
- assert_equal(nodelengths[0], nodelengths[1])
542
- assert(has_child2[1])
543
- assert(!has_child2[0])
544
- end
545
-
546
- def test_correct_inner_xml_inclusion
547
- xml = Nokogiri::XML::Reader.from_io(StringIO.new(<<-eoxml))
548
- <root-element>
549
- <children>
550
- <child n="1">
551
- <field>child-1</field>
552
- </child>
553
- <child n="2">
554
- <field>child-2</field>
555
- </child>
556
- <child n="3">
557
- <field>child-3</field>
558
- </child>
559
- </children>
560
- </root-element>
561
- eoxml
562
-
563
- nodelengths = []
564
- has_child2 = []
565
-
566
- xml.each do |node|
567
- if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT and node.name == "child"
568
- nodelengths << node.inner_xml.length
569
- has_child2 << !!(node.inner_xml =~ /child-2/)
570
- end
571
- end
572
-
573
- assert_equal(nodelengths[0], nodelengths[1])
574
- assert(has_child2[1])
575
- assert(!has_child2[0])
576
- end
577
- end