Fix encodeURIComponent on Ruby 1.8.

Replace .ord with .unpack('U')[0]
This commit is contained in:
bootstraponline
2012-08-22 17:23:08 -06:00
parent a5f9df6170
commit 686b8acd38
2 changed files with 9 additions and 1 deletions
+3 -1
View File
@@ -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
+6
View File
@@ -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, "# 한글")