Skip to content

Commit

Permalink
Fix Ox adapter incorrectly handling documents with XML declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
kgiszczak committed Nov 13, 2023
1 parent f93c846 commit 4946004
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
### Changed
- Drop support for Ruby 2.6 and Ruby 2.7

### Fixed
- Fix Ox adapter incorrectly handling documents with XML declaration

## [1.0.0] - 2023-07-15

### Added
Expand Down
3 changes: 2 additions & 1 deletion lib/shale/adapter/ox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ module Ox
#
# @api private
def self.load(xml)
Node.new(::Ox.parse(xml))
element = ::Ox.parse(xml)
Node.new(element.respond_to?(:root) ? element.root : element)
rescue ::Ox::ParseError => e
raise ParseError, "Document is invalid: #{e.message}"
end
Expand Down
7 changes: 7 additions & 0 deletions spec/shale/adapter/ox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
end
end

context 'with XML document containing declaration' do
it 'parses XML document' do
doc = described_class.load('<?xml version="1.0"?><foo></foo>')
expect(doc.name).to eq('foo')
end
end

context 'with invalid XML document' do
it 'raises an error' do
expect do
Expand Down

0 comments on commit 4946004

Please sign in to comment.