From 1be40495c2f8d0f41af5edc5bcf5659d27aa5bdd Mon Sep 17 00:00:00 2001 From: Tyler Brock Date: Tue, 14 Feb 2012 16:07:53 -0500 Subject: [PATCH] RUBY-412 added if statement to case T_DATA to catch unserializable time classes in Ruby >= 1.9.3 --- ext/cbson/cbson.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ext/cbson/cbson.c b/ext/cbson/cbson.c index 5d0db61..a60423b 100644 --- a/ext/cbson/cbson.c +++ b/ext/cbson/cbson.c @@ -469,6 +469,12 @@ static int write_element(VALUE key, VALUE value, VALUE extra, int allow_id) { SAFE_WRITE(buffer, (const char*)&time_since_epoch, 8); break; } + // Date classes are TYPE T_DATA in Ruby >= 1.9.3 + if (strcmp(cls, "DateTime") == 0 || strcmp(cls, "Date") == 0 || strcmp(cls, "ActiveSupport::TimeWithZone") == 0) { + bson_buffer_free(buffer); + rb_raise(InvalidDocument, "%s is not currently supported; use a UTC Time instance instead.", cls); + break; + } if(strcmp(cls, "BigDecimal") == 0) { bson_buffer_free(buffer); rb_raise(InvalidDocument, "Cannot serialize the Numeric type %s as BSON; only Bignum, Fixnum, and Float are supported.", cls);