Skip to content

Instantly share code, notes, and snippets.

@pzol
Created August 5, 2011 19:10
Show Gist options
  • Save pzol/1128267 to your computer and use it in GitHub Desktop.
Save pzol/1128267 to your computer and use it in GitHub Desktop.
ActiveSupport broken on UTF-8 strings
# encoding: UTF-8
# parsing with EOF throws illegal characters!?
json = <<EOF
{
"date_a": "2011-07-22T09:54:44Z",
"city": "wroc\u0142aw", # after this the next date is not parsed anymore!
"date_b": "2011-07-22T09:54:44Z"
}
EOF
# this json works
json2 = ' { "date_a": "2011-07-22T09:54:44Z", "city": "wroc\u0142aw", "date_b": "2011-07-22T09:54:44Z" }'
require 'active_support/json'
require 'oj'
ActiveSupport.parse_json_times = true
p ActiveSupport::JSON.backend
p ActiveSupport::JSON.decode(json2)
@wmaryszczak
Copy link

It parses date value into ruby DateTime object which is invalid for mongodb ruby driver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment