diff options
author | Bas Van Klinkenberg <bas@vanklinkenbergsoftware.nl> | 2009-08-01 02:24:40 +0200 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2009-08-08 12:44:41 -0300 |
commit | 0fbeaa98e4e60ca0949be298dae8545807407e1d (patch) | |
tree | 6675ab887da3598338f3bb26384d937c1574c208 /activesupport/lib/active_support/json | |
parent | d0301e13f4d6e2ddf956ecf80e85384c1ea5346c (diff) | |
download | rails-0fbeaa98e4e60ca0949be298dae8545807407e1d.tar.gz rails-0fbeaa98e4e60ca0949be298dae8545807407e1d.tar.bz2 rails-0fbeaa98e4e60ca0949be298dae8545807407e1d.zip |
Fixed a bug in JSON decoding with Yaml backend, where a combination of dates, escaped or unicode encoded data and arrays would make the parser fail with a ParseError exception. [#2831 state:resolved]
Signed-off-by: Yehuda Katz <wycats@gmail.com>
Diffstat (limited to 'activesupport/lib/active_support/json')
-rw-r--r-- | activesupport/lib/active_support/json/backends/yaml.rb | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/json/backends/yaml.rb b/activesupport/lib/active_support/json/backends/yaml.rb index 667016f45d..92dd31cfbc 100644 --- a/activesupport/lib/active_support/json/backends/yaml.rb +++ b/activesupport/lib/active_support/json/backends/yaml.rb @@ -34,11 +34,9 @@ module ActiveSupport pos = scanner.pos elsif quoting == char if json[pos..scanner.pos-2] =~ DATE_REGEX - # found a date, track the exact positions of the quotes so we can remove them later. - # oh, and increment them for each current mark, each one is an extra padded space that bumps - # the position in the final YAML output - total_marks = marks.size - times << pos+total_marks << scanner.pos+total_marks + # found a date, track the exact positions of the quotes so we can + # overwrite them with spaces later. + times << pos << scanner.pos end quoting = false end @@ -64,7 +62,12 @@ module ActiveSupport output = [] left_pos.each_with_index do |left, i| scanner.pos = left.succ - output << scanner.peek(right_pos[i] - scanner.pos + 1).gsub(/\\([\\\/]|u[[:xdigit:]]{4})/) do + chunk = scanner.peek(right_pos[i] - scanner.pos + 1) + # overwrite the quotes found around the dates with spaces + while times.size > 0 && times[0] <= right_pos[i] + chunk[times.shift - scanner.pos - 1] = ' ' + end + chunk.gsub!(/\\([\\\/]|u[[:xdigit:]]{4})/) do ustr = $1 if ustr.start_with?('u') [ustr[1..-1].to_i(16)].pack("U") @@ -74,10 +77,10 @@ module ActiveSupport ustr end end + output << chunk end output = output * " " - times.each { |i| output[i-1] = ' ' } output.gsub!(/\\\//, '/') output end |