This project is archived and is in readonly mode.
ActiveSupport::JSON.decode breaks for strings that look like dates ruby1.9.2
-
pederbl (at jobstar)
"{str
seems like lighthouse formatting has a problem with displaying json strings
-
pederbl (at jobstar)
ok here is another try:
{str
-
pederbl (at jobstar)
retry:
{ str: 1089-10-40 }
-
Repository
- State changed from new to resolved
(from [b17d8d727fb510ad8b6eb4302984d290dc2e53b0]) Fixes an issue when decoding a json string which looks like a date but is invalid. This DateTime parse error is now caught and the original string is instead passed back [#6286 ActiveSupport::JSON.decode breaks for strings that look like dates ruby1.9.2 state:resolved]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
https://github.com/rails/rails/commit/b17d8d727fb510ad8b6eb4302984d... -
pederbl (at jobstar)
Thanks for fixing this problem. However, I suggest that you should never convert string values to DateTime in the JSON parser. Generally, the current logic violates the Keep it Simple Smartypants (KISS) principle. Specifically, I will have to do the following unintuitive and cumbersome programming pattern because of the current logic:
hash = ActiveSupport::JSON.decode(json_string)
hash['reference'] = hash['reference'].to_s # make sure to convert DateTime to string if the string matched the datetime regexp in the parser.I will have to convert all string values to strings in the hash because otherwise something like the following might happen:
subject = "Product reference: #{hash['reference']}" # => "Product reference: 2011-02-12T00:00:00+00:00"
which would be incorrect. The expected value of subject should be: "Product reference: 2011-02-12" because the reference string just happens to look like a date but really isn't.
So by converting string values to DateTime in the parser you:
1) require a unintuitive and cumbersome programming pattern
2) make it hard to avoid bugs that are hard to find and debug and appear seldom.Also, by converting strings to DateTime the parse code become unnecessarily complicated which makes it harder to maintain increases the risk of bugs and makes it slower.
-
Repository
(from [e605165d16bc0eff8e4bea9865d9963b2d24dcf1]) Fixes an issue when decoding a json string which looks like a date but is invalid. This DateTime parse error is now caught and the original string is instead passed back [#6286 ActiveSupport::JSON.decode breaks for strings that look like dates ruby1.9.2 state:resolved]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
https://github.com/rails/rails/commit/e605165d16bc0eff8e4bea9865d99...