matches YAML-formatted dates
# File lib/crack/json.rb, line 11 def self.parse(json) YAML.load(unescape(convert_json_to_yaml(json))) rescue ArgumentError => e raise ParseError, "Invalid JSON string" end
# File lib/crack/json.rb, line 18 def self.unescape(str) # Force the encoding to be UTF-8 so we can perform regular expressions # on 1.9.2 without blowing up. # see http://stackoverflow.com/questions/1224204/ruby-mechanize-getting-force-encoding-exception for a similar issue str.force_encoding('UTF-8') if defined?(Encoding) && str.respond_to?(:force_encoding) str.gsub(%r\\u0000/, "").gsub(%r\\[u|U]([0-9a-fA-F]{4})/) { [$1.hex].pack("U") } end