Skip to content

Commit

Permalink
comment: clarify unhappiness with in-context node parsing
Browse files Browse the repository at this point in the history
and link to the github issue I just opened, #2092.

[skip ci]
  • Loading branch information
flavorjones committed Oct 8, 2020
1 parent 46a2147 commit 0dcf206
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/nokogiri/xml/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,21 @@ def parse(string_or_io, options = nil)

return Nokogiri::XML::NodeSet.new(document) if contents.empty?

##
# This is a horrible hack, but I don't care. See #313 for background.
# libxml2 does not obey the `recover` option after encountering errors during `in_context`
# parsing, and so this horrible hack is here to try to emulate recovery behavior.
#
# Unfortunately, this means we're no longer parsing "in context" and so namespaces that
# would have been inherited from the context node won't be handled correctly. This hack was
# writting in 2010, and I regret it, because it's silently degrading functionality in a way
# that's not easily prevented (or even detected).
#
# I think preferable behavior would be to either:
#
# a. add an error noting that we "fell back" and pointing the user to turning off the `recover` option
# b. don't recover, but raise a sensible exception
#
# For context and background: https://github.com/sparklemotion/nokogiri/issues/313
# FIXME bug report: https://github.com/sparklemotion/nokogiri/issues/2092
error_count = document.errors.length
node_set = in_context(contents, options.to_i)
if node_set.empty? and document.errors.length > error_count and options.recover?
Expand Down

0 comments on commit 0dcf206

Please sign in to comment.