test/spec_utils.rb in rack-1.3.0 vs test/spec_utils.rb in rack-1.3.1

- old
+ new

@@ -1,7 +1,6 @@ # -*- encoding: utf-8 -*- - require 'rack/utils' require 'rack/mock' describe Rack::Utils do should "escape correctly" do @@ -18,10 +17,32 @@ matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8".unpack("a*")[0] # Matsu moto matz_name_sep.force_encoding("UTF-8") if matz_name_sep.respond_to? :force_encoding Rack::Utils.escape(matz_name_sep).should.equal '%E3%81%BE%E3%81%A4+%E3%82%82%E3%81%A8' end + if RUBY_VERSION[/^\d+\.\d+/] == '1.8' + should "escape correctly for multibyte characters if $KCODE is set to 'U'" do + default_kcode, $KCODE = $KCODE, 'U' + + matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8".unpack("a*")[0] # Matsumoto + matz_name.force_encoding("UTF-8") if matz_name.respond_to? :force_encoding + Rack::Utils.escape(matz_name).should.equal '%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8' + matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8".unpack("a*")[0] # Matsu moto + matz_name_sep.force_encoding("UTF-8") if matz_name_sep.respond_to? :force_encoding + Rack::Utils.escape(matz_name_sep).should.equal '%E3%81%BE%E3%81%A4+%E3%82%82%E3%81%A8' + + $KCODE = default_kcode + end + + should "unescape multibyte characters correctly if $KCODE is set to 'U'" do + default_kcode, $KCODE = $KCODE, 'U' + Rack::Utils.unescape('%E3%81%BE%E3%81%A4+%E3%82%82%E3%81%A8').should.equal( + "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8".unpack("a*")[0]) + $KCODE = default_kcode + end + end + if "".respond_to?(:encode) should "escape non-UTF8 strings" do Rack::Utils.escape("ΓΈ".encode("ISO-8859-1")).should.equal "%F8" end end @@ -74,10 +95,10 @@ should.equal "foo" => nil, "bar" => "" Rack::Utils.parse_nested_query("foo=bar&baz="). should.equal "foo" => "bar", "baz" => "" Rack::Utils.parse_nested_query("my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F"). should.equal "my weird field" => "q1!2\"'w$5&7/z8)?" - + Rack::Utils.parse_nested_query("a=b&pid%3D1234=1023"). should.equal "pid=1234" => "1023", "a" => "b" Rack::Utils.parse_nested_query("foo[]"). should.equal "foo" => [nil]