Q:

Preventing Nokogiri from escaping characters in URLs

Nokogiri("<a href='*|UNSUB|*'>unsubscribe</a>").to_html
# returns
"<a href="*%7CUNSUB%7C*">unsubscribe</a>"

How can I get Nokogiri to not escape the pipes? 

A:

require 'nokogiri'

doc = Nokogiri("<a href='*|UNSUB|*'>unsubscribe</a>")

puts doc.to_html
#=> <a href="*%7CUNSUB%7C*">unsubscribe</a>

puts doc.to_xml
#=> <? xml version="1.0"? >
#=> <a href="*|UNSUB|*">unsubscribe</a>

Alternatively:
puts doc.to_html.gsub('%7C','|')
#=> <a href="*|UNSUB|*">unsubscribe</a>

