Skip to content

Commit

Permalink
Fix parsing for strings that contain newlines
Browse files Browse the repository at this point in the history
Closes #5
  • Loading branch information
sferik committed Oct 16, 2010
1 parent 91fb29b commit 68087a4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/multi_xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def typecast_xml_value(value)
when Hash
if value['type'] == 'array'
_, entries = wrap(value.detect{|key, value| key != 'type'})
if entries.nil? || entries.strip.empty? || (c = value[CONTENT_ROOT] && c.blank?)
if entries.blank? || (c = value[CONTENT_ROOT] && c.blank?)
[]
else
case entries
Expand Down
12 changes: 6 additions & 6 deletions lib/multi_xml/core_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Object #:nodoc:
# Returns true if the object is nil or empty (if applicable)
def blank?
nil? || (respond_to?(:empty?) && empty?)
end unless method_defined?(:blank?)
end
end

class Numeric #:nodoc:
Expand All @@ -17,7 +17,7 @@ class Numeric #:nodoc:
# Numerics can't be blank
def blank?
false
end unless method_defined?(:blank?)
end
end

class NilClass #:nodoc:
Expand All @@ -26,7 +26,7 @@ class NilClass #:nodoc:
# Nils are always blank
def blank?
true
end unless method_defined?(:blank?)
end
end

class TrueClass #:nodoc:
Expand All @@ -35,14 +35,14 @@ class TrueClass #:nodoc:
# True is not blank.
def blank?
false
end unless method_defined?(:blank?)
end
end

class FalseClass #:nodoc:
# False is always blank.
def blank?
true
end unless method_defined?(:blank?)
end
end

class String #:nodoc:
Expand All @@ -55,5 +55,5 @@ class String #:nodoc:
# Strips out whitespace then tests if the string is empty.
def blank?
strip.empty?
end unless method_defined?(:blank?)
end
end
4 changes: 1 addition & 3 deletions lib/multi_xml/parsers/rexml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ def parse(xml)
else
xml.ungetc(char)
doc = REXML::Document.new(xml)

if doc.root
merge_element!({}, doc.root)
else
raise REXML::ParseException,
"The document #{doc.to_s.inspect} does not have a valid root"
raise REXML::ParseException, "The document #{doc.to_s.inspect} does not have a valid root"
end
end
end
Expand Down
1 change: 0 additions & 1 deletion spec/multi_xml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ def self.parse(xml)
end

it "should parse correctly" do
pending
MultiXml.parse(@xml).should == {"user"=>{"name"=>"Erik Michaels-Ober"}}
end
end
Expand Down

0 comments on commit 68087a4

Please sign in to comment.