Skip to content

Commit

Permalink
Add recovery option to SAX parser
Browse files Browse the repository at this point in the history
  • Loading branch information
mullermp committed Aug 5, 2024
1 parent ba75fe2 commit d7e199e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ def initialize(stack)
end

def parse(xml)
Nokogiri::XML::SAX::Parser.new(self).parse(xml)
p = Nokogiri::XML::SAX::Parser.new(self)
p.parse(xml) do |ctx|
ctx.recovery = true
end
end

def xmldecl(*args); end
Expand Down
17 changes: 8 additions & 9 deletions gems/aws-sdk-core/spec/aws/xml/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@ module Xml
describe Parser do
[:ox, :oga, :nokogiri, :libxml, :rexml].each do |engine|
describe("ENGINE: #{engine}") do

begin
Parser.engine = engine
rescue LoadError
next
end

let(:shapes) { ApiHelper.sample_shapes }

let(:parser) {
let(:parser) do
api = ApiHelper.sample_api(shapes:shapes)
rules = api.operation(:example_operation).output
Parser.engine = engine
Parser.new(rules)
}
end

def parse(xml, to_h = true)
data = parser.parse(xml)
Expand Down Expand Up @@ -410,6 +404,11 @@ def parse(xml, to_h = true)
expect(parse(xml)).to eq(string: 'a', nested: { string: 'b' })
end

it 'handles boundary characters' do
xml = "<xml><String>foo\bbar</String></xml>"
expect(parse(xml)).to eq(string: "foo\bbar")
end

end

describe 'xml attributes' do
Expand Down

0 comments on commit d7e199e

Please sign in to comment.