Skip to content

Commit

Permalink
strip incoming xml (fixes #16)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiii committed Dec 12, 2012
1 parent 7e7bfca commit f1cb225
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Please make sure to read the updated README for how to use the new version.
* Refactoring: Removed the `Nori::Parser` module methods. After refactoring the rest,
there was only a single method left for this module and that was moved to `Nori`.

* Fix: [#16](https://github.com/savonrb/nori/issues/16) strip XML passed to Nori.

## 1.1.3 (2012-07-12)

* Fix: Merged [pull request 21](https://github.com/savonrb/nori/pull/21) to fix an
Expand Down
5 changes: 4 additions & 1 deletion lib/nori.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ def initialize(options = {})
end

def parse(xml)
cleaned_xml = xml.strip
return {} if cleaned_xml.empty?

parser = load_parser @options[:parser]
parser.parse(xml, @options)
parser.parse(cleaned_xml, @options)
end

private
Expand Down
2 changes: 0 additions & 2 deletions lib/nori/parser/nokogiri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ def characters(string)
end

def self.parse(xml, options)
return {} if xml.strip.empty?

document = Document.new
document.options = options
parser = ::Nokogiri::XML::SAX::Parser.new document
Expand Down
7 changes: 7 additions & 0 deletions spec/nori/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
Nori::Parser::Nokogiri.should_receive(:parse).once
nori.parse("<any>thing</any>")
end

it "strips the XML" do
xml = double("xml")
xml.should_receive(:strip).and_return("<any>thing</any>")

nori.parse(xml).should == { "any" => "thing" }
end
end

context "#parse without :advanced_typecasting" do
Expand Down

0 comments on commit f1cb225

Please sign in to comment.