ox
ox copied to clipboard
Invalid name for an orphan end tag
In some conditions, a final orphan end tag is reported to the Sax handler incorrectly:
➜ echo -n "</root>" | bundle exec test.rb
start_element: 'roo'
end_element: 'roo'
Even worse, when the orphan end tag is empty, the name can't be built and causes this error:
➜ echo -n "</>" | bundle exec test.rb
bundler: failed to load command: test.rb (test.rb)
test.rb:10:in `sax_parse': negative string size (or size too big) (ArgumentError)
Ox.sax_parse(Handler.new, StringIO.new(STDIN.read))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
from test.rb:10:in `<top (required)>'
from /home/user/Projects/ox-test/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.6/lib/bundler/cli/exec.rb:58:in `load'
from /home/user/Projects/ox-test/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.6/lib/bundler/cli/exec.rb:58:in `kernel_load'
from /home/user/Projects/ox-test/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.6/lib/bundler/cli/exec.rb:23:in `run'
from /home/user/Projects/ox-test/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.6/lib/bundler/cli.rb:451:in `exec'
from /home/user/Projects/ox-test/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.6/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
from /home/user/Projects/ox-test/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.6/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
from /home/user/Projects/ox-test/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.6/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
from /home/user/Projects/ox-test/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.6/lib/bundler/cli.rb:34:in `dispatch'
from /home/user/Projects/ox-test/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.6/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
from /home/user/Projects/ox-test/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.6/lib/bundler/cli.rb:28:in `start'
from /home/user/Projects/ox-test/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.6/exe/bundle:28:in `block in <top (required)>'
from /home/user/Projects/ox-test/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.6/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
from /home/user/Projects/ox-test/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.6/exe/bundle:20:in `<top (required)>'
from /home/user/.rbenv/versions/3.3.0/bin/bundle:25:in `load'
from /home/user/.rbenv/versions/3.3.0/bin/bundle:25:in `<main>
➜ echo -n "<root></root></>" | bundle exec test.rb
start_element: 'root'
end_element: 'root'
bundler: failed to load command: test.rb (test.rb)
test.rb:10:in `sax_parse': negative string size (or size too big) (ArgumentError)
...
This problem doesn't occur when the XML payload contains any character after the end tag:
➜ echo -n "</> " | bundle exec test.rb
start_element: ''
end_element: ''
➜ echo "</>" | bundle exec test.rb
start_element: ''
end_element: ''
➜ echo "</root>" | bundle exec test.rb
start_element: 'root'
end_element: 'root'
Context
- Ox: 2.14.17
- Ruby: 3.3 or 2.7.8
The tiny test.rb
used to parse the given input:
#!/usr/bin/env ruby
require 'ox'
class Handler
def start_element(name); puts "start_element: '#{name}'"; end
def end_element(name); puts "end_element: '#{name}'"; end
end
Ox.sax_parse(Handler.new, StringIO.new(STDIN.read))