Encoding issue when using Nokogiri replace
问题 I have this code: # encoding: utf-8 require 'nokogiri' s = "<a href='/path/to/file'>Café Verona</a>".encode('UTF-8') puts "Original string: #{s}" @doc = Nokogiri::HTML::DocumentFragment.parse(s) links = @doc.css('a') only_text = 'Café Verona'.encode('UTF-8') puts "Replacement text: #{only_text}" links.first.replace(only_text) puts @doc.to_html However, the output is this: Original string: <a href='/path/to/file'>Café Verona</a> Replacement text: Café Verona Café Verona Why does the text in