1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Use explicit source encoding rather than forced UTF-8 from US-ASCII.

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
Santiago Pastorino 2010-04-26 11:50:18 -03:00 committed by Jeremy Kemper
parent 53c13f1aca
commit 76d6a99364
4 changed files with 4 additions and 5 deletions

View file

@ -866,7 +866,6 @@ EOF
regex = Regexp.escape('Subject: Foo =?UTF-8?Q?=C3=A1=C3=AB=C3=B4=?= =?UTF-8?Q?_=C3=AE=C3=BC=?=') regex = Regexp.escape('Subject: Foo =?UTF-8?Q?=C3=A1=C3=AB=C3=B4=?= =?UTF-8?Q?_=C3=AE=C3=BC=?=')
assert_match(/#{regex}/, mail.encoded) assert_match(/#{regex}/, mail.encoded)
string = "Foo áëô îü" string = "Foo áëô îü"
string.force_encoding('UTF-8') if string.respond_to?(:force_encoding)
assert_match(string, mail.subject) assert_match(string, mail.subject)
end end
@ -875,7 +874,6 @@ EOF
regex = Regexp.escape('Subject: Foo =?UTF-8?Q?=C3=A1=C3=AB=C3=B4=?= =?UTF-8?Q?_=C3=AE=C3=BC=?=') regex = Regexp.escape('Subject: Foo =?UTF-8?Q?=C3=A1=C3=AB=C3=B4=?= =?UTF-8?Q?_=C3=AE=C3=BC=?=')
assert_match(/#{regex}/, mail.encoded) assert_match(/#{regex}/, mail.encoded)
string = "Foo áëô îü" string = "Foo áëô îü"
string.force_encoding('UTF-8') if string.respond_to?(:force_encoding)
assert_match(string, mail.subject) assert_match(string, mail.subject)
end end

View file

@ -1,8 +1,9 @@
# encoding: utf-8
if RUBY_VERSION >= '1.9' if RUBY_VERSION >= '1.9'
require 'uri' require 'uri'
str = "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E" # Ni-ho-nn-go in UTF-8, means Japanese. str = "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E" # Ni-ho-nn-go in UTF-8, means Japanese.
str.force_encoding(Encoding::UTF_8) if str.respond_to?(:force_encoding)
parser = URI::Parser.new parser = URI::Parser.new
unless str == parser.unescape(parser.escape(str)) unless str == parser.unescape(parser.escape(str))

View file

@ -1,3 +1,4 @@
# encoding: utf-8
require 'abstract_unit' require 'abstract_unit'
require 'uri' require 'uri'
require 'active_support/core_ext/uri' require 'active_support/core_ext/uri'
@ -5,7 +6,6 @@ require 'active_support/core_ext/uri'
class URIExtTest < Test::Unit::TestCase class URIExtTest < Test::Unit::TestCase
def test_uri_decode_handle_multibyte def test_uri_decode_handle_multibyte
str = "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E" # Ni-ho-nn-go in UTF-8, means Japanese. str = "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E" # Ni-ho-nn-go in UTF-8, means Japanese.
str.force_encoding(Encoding::UTF_8) if str.respond_to?(:force_encoding)
if URI.const_defined?(:Parser) if URI.const_defined?(:Parser)
parser = URI::Parser.new parser = URI::Parser.new

View file

@ -105,7 +105,7 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
@whitespace = "\n\t#{[32, 8195].pack('U*')}" @whitespace = "\n\t#{[32, 8195].pack('U*')}"
else else
# Ruby 1.9 only supports basic whitespace # Ruby 1.9 only supports basic whitespace
@whitespace = "\n\t ".force_encoding(Encoding::UTF_8) @whitespace = "\n\t "
end end
@byte_order_mark = [65279].pack('U') @byte_order_mark = [65279].pack('U')