From 7ce849a2b6fca299627849560ff36902321c51a5 Mon Sep 17 00:00:00 2001 From: Alberto Grespan Date: Tue, 20 May 2014 00:03:40 -0430 Subject: [PATCH] Revert changes and add encoding to the test file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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. --- lib/jekyll/url.rb | 4 ++-- test/test_post.rb | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/jekyll/url.rb b/lib/jekyll/url.rb index 31186d45..f4ea4d33 100644 --- a/lib/jekyll/url.rb +++ b/lib/jekyll/url.rb @@ -89,7 +89,7 @@ module Jekyll # pct-encoded = "%" HEXDIG HEXDIG # 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 # Unescapes a URL path segment @@ -103,7 +103,7 @@ module Jekyll # # Returns the unescaped path. def self.unescape_path(path) - URI.unescape(path.force_encoding('utf-8')) + URI.unescape(path.encode('utf-8')) end end end diff --git a/test/test_post.rb b/test/test_post.rb index c52232cd..46d1fa7e 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + require 'helper' class TestPost < Test::Unit::TestCase @@ -101,11 +103,11 @@ class TestPost < Test::Unit::TestCase end 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 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 should "respect permalink in yaml front matter" do