Ruby 1.9: force ascii encoding for comparison with utf8 regexp

This commit is contained in:
Jeremy Kemper 2009-02-03 18:41:06 -08:00
parent 278186534c
commit bdaf3348de
1 changed files with 2 additions and 0 deletions

View File

@ -617,6 +617,8 @@ module ActiveSupport #:nodoc:
# Replaces all ISO-8859-1 or CP1252 characters by their UTF-8 equivalent resulting in a valid UTF-8 string.
def tidy_bytes(string)
string.split(//u).map do |c|
c.force_encoding(Encoding::ASCII) if c.respond_to?(:force_encoding)
if !UTF8_PAT.match(c)
n = c.unpack('C')[0]
n < 128 ? n.chr :