Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add line column to message #1304

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/nokogiri/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def engine
defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'mri'
end

def rbx?
RUBY_ENGINE == 'rbx'
end

def loaded_parser_version
LIBXML_PARSER_VERSION.scan(/^(\d+)(\d\d)(\d\d)(?!\d)/).first.collect{ |j|
j.to_i
Expand Down Expand Up @@ -105,4 +109,8 @@ def self.uses_libxml? # :nodoc:
def self.jruby? # :nodoc:
VersionInfo.instance.jruby?
end

def self.rbx? # :nodoc:
VersionInfo.instance.rbx?
end
end
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
1 change: 1 addition & 0 deletions test/html/test_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ def test_empty_document
end

def test_capturing_nonparse_errors_during_document_clone
skip("Rubinius does not dup column, bug?") if Nokogiri.rbx?
# see https://github.com/sparklemotion/nokogiri/issues/1196 for background
original = Nokogiri::HTML.parse("<div id='unique'></div><div id='unique'></div>")
original_errors = original.errors.dup
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 unless Nokogiri.jruby? # which does not internally call `errors`
end
end
end