Revert changes and add encoding to the test file

* Add encoding to the test file as Ruby 1.9.3 doesn’t defaults to utf-8.
* Remove the forced encoding as encode seems too aggressive.
This commit is contained in:
Alberto Grespan 2014-05-20 00:03:40 -04:30
parent 2a1054b1a8
commit 7ce849a2b6
2 changed files with 6 additions and 4 deletions

View File

@ -89,7 +89,7 @@ module Jekyll
# pct-encoded = "%" HEXDIG HEXDIG # pct-encoded = "%" HEXDIG HEXDIG
# sub-delims = "!" / "$" / "&" / "'" / "(" / ")" # sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
# / "*" / "+" / "," / ";" / "=" # / "*" / "+" / "," / ";" / "="
URI.escape(path.force_encoding('utf-8'), /[^a-zA-Z\d\-._~!$&\'()*+,;=:@\/]/).encode('utf-8') URI.escape(path, /[^a-zA-Z\d\-._~!$&\'()*+,;=:@\/]/).encode('utf-8')
end end
# Unescapes a URL path segment # Unescapes a URL path segment
@ -103,7 +103,7 @@ module Jekyll
# #
# Returns the unescaped path. # Returns the unescaped path.
def self.unescape_path(path) def self.unescape_path(path)
URI.unescape(path.force_encoding('utf-8')) URI.unescape(path.encode('utf-8'))
end end
end end
end end

View File

@ -1,3 +1,5 @@
# encoding: utf-8
require 'helper' require 'helper'
class TestPost < Test::Unit::TestCase class TestPost < Test::Unit::TestCase
@ -101,11 +103,11 @@ class TestPost < Test::Unit::TestCase
end end
should "return a UTF-8 escaped string" do should "return a UTF-8 escaped string" do
assert_equal Encoding::UTF_8, URL.escape_path("/2014/04/20/escaped/").encoding assert_equal Encoding::UTF_8, URL.escape_path("/rails笔记/2014/04/20/escaped/").encoding
end end
should "return a UTF-8 unescaped string" do should "return a UTF-8 unescaped string" do
assert_equal Encoding::UTF_8, URL.unescape_path("/2014/04/20/escaped/").encoding assert_equal Encoding::UTF_8, URL.unescape_path("/rails%E7%AC%94%E8%AE%B0/2014/04/20/escaped/").encoding
end end
should "respect permalink in yaml front matter" do should "respect permalink in yaml front matter" do