From 686b8acd38c72ce04193ac6a59ea30a899be720d Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Wed, 22 Aug 2012 17:23:08 -0600 Subject: [PATCH] Fix encodeURIComponent on Ruby 1.8. Replace .ord with .unpack('U')[0] --- lib/gollum/frontend/uri_encode_component.rb | 4 +++- test/test_unicode.rb | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/gollum/frontend/uri_encode_component.rb b/lib/gollum/frontend/uri_encode_component.rb index f6891a7c..dcaabcd7 100644 --- a/lib/gollum/frontend/uri_encode_component.rb +++ b/lib/gollum/frontend/uri_encode_component.rb @@ -1,3 +1,4 @@ +# ~*~ encoding: utf-8 ~*~ =begin Copyright 2006-2008 the V8 project authors. All rights reserved. Redistribution and use in source and binary forms, with or without @@ -39,7 +40,8 @@ end # define charCodeAt on String class String def charCodeAt(k) - return self[k].ord + # 'str'.ord is broken on 1.8 + return self[k].unpack('U')[0] end end diff --git a/test/test_unicode.rb b/test/test_unicode.rb index 86860f71..8b478436 100644 --- a/test/test_unicode.rb +++ b/test/test_unicode.rb @@ -15,6 +15,12 @@ context "Unicode Support" do FileUtils.rm_rf(@path) end + test "uri encode" do + c = '한글' + assert_equal '%ED%95%9C%EA%B8%80', encodeURIComponent(c) + assert_equal '%ED%95%9C%EA%B8%80', CGI::escape(c) + end + test "create and read non-latin page with anchor" do @wiki.write_page("test", :markdown, "# 한글")