Commit d650b19f authored by Jerry Cheung's avatar Jerry Cheung

Merge pull request #40 from jch/no-nokogiri-monkeypatch-in-19

Don't monkeypatch Nokogiri in 1.9
parents fbb51e54 8ac4a82b
......@@ -108,23 +108,25 @@ module HTML
end
end
# XXX nokogiri monkey patches
class Nokogiri::XML::Node
# Work around an issue with utf-8 encoded data being erroneously converted to
# ... some other shit when replacing text nodes. See 'utf-8 output 2' in
# user_content_test.rb for details.
def replace_with_encoding_fix(replacement)
if replacement.respond_to?(:to_str)
replacement = document.fragment("<div>#{replacement}</div>").children.first.children
# XXX nokogiri monkey patches for 1.8
if not ''.respond_to?(:force_encoding)
class Nokogiri::XML::Node
# Work around an issue with utf-8 encoded data being erroneously converted to
# ... some other shit when replacing text nodes. See 'utf-8 output 2' in
# user_content_test.rb for details.
def replace_with_encoding_fix(replacement)
if replacement.respond_to?(:to_str)
replacement = document.fragment("<div>#{replacement}</div>").children.first.children
end
replace_without_encoding_fix(replacement)
end
replace_without_encoding_fix(replacement)
end
alias_method :replace_without_encoding_fix, :replace
alias_method :replace, :replace_with_encoding_fix
alias_method :replace_without_encoding_fix, :replace
alias_method :replace, :replace_with_encoding_fix
def swap(replacement)
replace(replacement)
self
def swap(replacement)
replace(replacement)
self
end
end
end
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment