Permalink
Browse files

Ruby 1.9 compat: fix JSON decoding to work properly with multibyte va…

…lues

[#1969 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
1 parent b0792a3 commit 13bf5c5a6ae510cd17f05ac24cad5df9dda42342 @amatsuda amatsuda committed with jeremy Feb 14, 2009
Showing with 6 additions and 2 deletions.
  1. +3 −2 activesupport/lib/active_support/json/decoding.rb
  2. +3 −0 activesupport/test/json/decoding_test.rb
View
5 activesupport/lib/active_support/json/decoding.rb
@@ -46,10 +46,11 @@ def convert_json_to_yaml(json) #:nodoc:
json.gsub(/\\\//, '/')
else
left_pos = [-1].push(*marks)
- right_pos = marks << json.length
+ right_pos = marks << scanner.pos + scanner.rest_size
output = []
left_pos.each_with_index do |left, i|
- output << json[left.succ..right_pos[i]]
+ scanner.pos = left.succ
+ output << scanner.peek(right_pos[i] - scanner.pos + 1)
end
output = output * " "
View
3 activesupport/test/json/decoding_test.rb
@@ -1,3 +1,4 @@
+# encoding: UTF-8
require 'abstract_unit'
class TestJSONDecoding < Test::Unit::TestCase
@@ -10,6 +11,8 @@ class TestJSONDecoding < Test::Unit::TestCase
%({"returnTo":[1,"\\"a\\",", "b"]}) => {"returnTo" => [1, "\"a\",", "b"]},
%({a: "'", "b": "5,000"}) => {"a" => "'", "b" => "5,000"},
%({a: "a's, b's and c's", "b": "5,000"}) => {"a" => "a's, b's and c's", "b" => "5,000"},
+ # multibyte
+ %({"matzue": "松江", "asakusa": "浅草"}) => {"matzue" => "松江", "asakusa" => "浅草"},
%({a: "2007-01-01"}) => {'a' => Date.new(2007, 1, 1)},
%({a: "2007-01-01 01:12:34 Z"}) => {'a' => Time.utc(2007, 1, 1, 1, 12, 34)},
# no time zone

0 comments on commit 13bf5c5

Please sign in to comment.