Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
279 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,2 @@ | ||
require 'active_support/core_ext/module/delegation' | ||
require 'active_support/core_ext/module/attribute_accessors' | ||
|
||
module ActiveSupport | ||
# If true, use ISO 8601 format for dates and times. Otherwise, fall back to the Active Support legacy format. | ||
mattr_accessor :use_standard_json_time_format | ||
# Look for and parse json strings that look like ISO 8601 times. | ||
mattr_accessor :parse_json_times | ||
|
||
module JSON | ||
# matches YAML-formatted dates | ||
DATE_REGEX = /^(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{1,2}-\d{1,2}[ \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?))$/ | ||
|
||
module Encoding #:nodoc: | ||
mattr_accessor :escape_regex | ||
|
||
ESCAPED_CHARS = { | ||
"\010" => '\b', | ||
"\f" => '\f', | ||
"\n" => '\n', | ||
"\r" => '\r', | ||
"\t" => '\t', | ||
'"' => '\"', | ||
'\\' => '\\\\', | ||
'>' => '\u003E', | ||
'<' => '\u003C', | ||
'&' => '\u0026' | ||
} | ||
|
||
def self.escape(string) | ||
string = string.dup.force_encoding(::Encoding::BINARY) if string.respond_to?(:force_encoding) | ||
json = string.gsub(escape_regex) { |s| ESCAPED_CHARS[s] }. | ||
gsub(/([\xC0-\xDF][\x80-\xBF]| | ||
[\xE0-\xEF][\x80-\xBF]{2}| | ||
[\xF0-\xF7][\x80-\xBF]{3})+/nx) { |s| | ||
s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/, '\\\\u\&') | ||
} | ||
%("#{json}") | ||
end | ||
end | ||
|
||
class << self | ||
delegate :decode, :to => :backend | ||
|
||
def backend | ||
unless defined? @backend | ||
self.backend = defined?(::JSON) ? "JSONGem" : "Yaml" | ||
end | ||
@backend | ||
end | ||
|
||
def backend=(name) | ||
if name.is_a?(Module) | ||
@backend = name | ||
else | ||
require "active_support/json/backends/#{name.to_s.downcase}.rb" | ||
@backend = ActiveSupport::JSON::Backends::const_get(name) | ||
end | ||
end | ||
|
||
def with_backend(name) | ||
old_backend, self.backend = backend, name | ||
yield | ||
ensure | ||
self.backend = old_backend | ||
end | ||
end | ||
end | ||
|
||
class << self | ||
attr_reader :escape_html_entities_in_json | ||
|
||
def escape_html_entities_in_json=(value) | ||
ActiveSupport::JSON::Encoding.escape_regex = \ | ||
if value | ||
/[\010\f\n\r\t"\\><&]/ | ||
else | ||
/[\010\f\n\r\t"\\]/ | ||
end | ||
@escape_html_entities_in_json = value | ||
end | ||
end | ||
end | ||
|
||
ActiveSupport.escape_html_entities_in_json = true | ||
|
||
require 'active_support/json/decoding' | ||
require 'active_support/json/encoding' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'active_support/core_ext/module/attribute_accessors' | ||
|
||
module ActiveSupport | ||
# Look for and parse json strings that look like ISO 8601 times. | ||
mattr_accessor :parse_json_times | ||
|
||
module JSON | ||
class << self | ||
delegate :decode, :to => :backend | ||
|
||
def backend | ||
@backend || begin | ||
self.backend = "Yaml" | ||
@backend | ||
end | ||
end | ||
|
||
def backend=(name) | ||
if name.is_a?(Module) | ||
@backend = name | ||
else | ||
require "active_support/json/backends/#{name.to_s.downcase}.rb" | ||
@backend = ActiveSupport::JSON::Backends::const_get(name) | ||
end | ||
end | ||
|
||
def with_backend(name) | ||
old_backend, self.backend = backend, name | ||
yield | ||
ensure | ||
self.backend = old_backend | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
activesupport/lib/active_support/json/encoders/date_time.rb
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
activesupport/lib/active_support/json/encoders/enumerable.rb
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
activesupport/lib/active_support/json/encoders/false_class.rb
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.