diff options
Diffstat (limited to 'activesupport/lib/active_support/json/decoding.rb')
-rw-r--r-- | activesupport/lib/active_support/json/decoding.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/json/decoding.rb b/activesupport/lib/active_support/json/decoding.rb index 0e079341ff..c66500aa9c 100644 --- a/activesupport/lib/active_support/json/decoding.rb +++ b/activesupport/lib/active_support/json/decoding.rb @@ -1,5 +1,7 @@ -require 'yaml' -require 'strscan' +autoload :YAML, 'yaml' unless defined? YAML +autoload :StringScanner, 'strscan' unless defined? StringScanner + +require 'active_support/core_ext/string/starts_ends_with' module ActiveSupport module JSON @@ -45,7 +47,7 @@ module ActiveSupport if marks.empty? json.gsub(/\\([\\\/]|u[[:xdigit:]]{4})/) do ustr = $1 - if ustr.starts_with?('u') + if ustr.start_with?('u') [ustr[1..-1].to_i(16)].pack("U") elsif ustr == '\\' '\\\\' @@ -61,10 +63,10 @@ module ActiveSupport scanner.pos = left.succ output << scanner.peek(right_pos[i] - scanner.pos + 1).gsub(/\\([\\\/]|u[[:xdigit:]]{4})/) do ustr = $1 - if ustr.starts_with?('u') + if ustr.start_with?('u') [ustr[1..-1].to_i(16)].pack("U") elsif ustr == '\\' - '\\\\' + '\\\\' else ustr end |