Skip to content

Commit

Permalink
Add line column to message
Browse files Browse the repository at this point in the history
Useful for `map(&:to_s)` and simple output
  • Loading branch information
spk committed Jun 18, 2015
1 parent 1be8831 commit 43d4955
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/nokogiri/xml/syntax_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def fatal?
end

def to_s
super.chomp
[super.chomp, line, column].compact.join(', ')
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/xml/test_entity_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def setup
end
assert_kind_of Nokogiri::XML::EntityReference, doc.xpath('//body').first.children.first
if Nokogiri.uses_libxml?
assert_equal ["Entity 'bar' not defined"], doc.errors.map(&:to_s)
assert_equal ["Entity 'bar' not defined, 5, 14"], doc.errors.map(&:to_s)
end
end

Expand All @@ -159,7 +159,7 @@ def setup
end
assert_kind_of Nokogiri::XML::EntityReference, doc.xpath('//body').first.children.first
if Nokogiri.uses_libxml?
assert_equal ["Attempt to load network entity http://foo.bar.com/", "Entity 'bar' not defined"], doc.errors.map(&:to_s)
assert_equal ["Attempt to load network entity http://foo.bar.com/, 0, 0", "Entity 'bar' not defined, 4, 34"], doc.errors.map(&:to_s)
else
assert_equal ["Attempt to load network entity http://foo.bar.com/"], doc.errors.map(&:to_s)
end
Expand Down
8 changes: 8 additions & 0 deletions test/xml/test_syntax_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def reader.errors
reader.read
}
end unless Nokogiri.jruby? # which does not internally call `errors`

def test_line_column
bad_doc = Nokogiri::XML('test')
error = bad_doc.errors.first
assert_equal "Start tag expected, '<' not found, 1, 1", error.message
assert_equal 1, error.line
assert_equal 1, error.column
end
end
end
end

0 comments on commit 43d4955

Please sign in to comment.