diff --git a/ext/cbson/cbson.c b/ext/cbson/cbson.c index 8a1de48..05048eb 100644 --- a/ext/cbson/cbson.c +++ b/ext/cbson/cbson.c @@ -62,6 +62,7 @@ static VALUE DBRef; static VALUE Code; static VALUE MinKey; static VALUE MaxKey; +static VALUE Regexp; static VALUE RegexpOfHolding; static VALUE OrderedHash; static VALUE InvalidName; @@ -693,8 +694,13 @@ static VALUE get_value(const char* buffer, int* position, int type) { } argv[0] = pattern; argv[1] = INT2FIX(flags); - argv[2] = rb_str_new2(extra); - value = rb_class_new_instance(3, argv, RegexpOfHolding); + if(extra[0] == 0) { + value = rb_class_new_instance(2, argv, Regexp); + } + else { // Deserializing a RegexpOfHolding + argv[2] = rb_str_new2(extra); + value = rb_class_new_instance(3, argv, RegexpOfHolding); + } *position += flags_length + 1; break; } @@ -877,6 +883,7 @@ void Init_cbson() { MinKey = rb_const_get(mongo, rb_intern("MinKey")); MaxKey = rb_const_get(mongo, rb_intern("MaxKey")); rb_require("mongo/types/regexp_of_holding"); + Regexp = rb_const_get(rb_cObject, rb_intern("Regexp")); RegexpOfHolding = rb_const_get(mongo, rb_intern("RegexpOfHolding")); rb_require("mongo/exceptions"); InvalidName = rb_const_get(mongo, rb_intern("InvalidName")); diff --git a/lib/mongo/util/bson_ruby.rb b/lib/mongo/util/bson_ruby.rb index f6a85f5..a28bf29 100644 --- a/lib/mongo/util/bson_ruby.rb +++ b/lib/mongo/util/bson_ruby.rb @@ -329,7 +329,12 @@ class BSON_RUBY options |= Regexp::MULTILINE if options_str.include?('m') options |= Regexp::EXTENDED if options_str.include?('x') options_str.gsub!(/[imx]/, '') # Now remove the three we understand - RegexpOfHolding.new(str, options, options_str) + if options_str == '' + Regexp.new(str, options) + else + warn("Use deprecated Regexp options #{options_str}; future versions of this MongoDB driver will support only i, m, and x. See deprecated class RegexpOfHolding for more info.") + RegexpOfHolding.new(str, options, options_str) + end end def deserialize_string_data(buf) diff --git a/test/test_bson.rb b/test/test_bson.rb index a0d5f4d..9413565 100644 --- a/test/test_bson.rb +++ b/test/test_bson.rb @@ -138,10 +138,9 @@ class BSONTest < Test::Unit::TestCase assert_equal doc, doc2 r = doc2['doc'] - assert_kind_of RegexpOfHolding, r - assert_equal '', r.extra_options_str + assert_kind_of Regexp, r - r.extra_options_str << 'zywcab' + r = RegexpOfHolding.new('st', 0, 'zywcab') assert_equal 'zywcab', r.extra_options_str doc = {'doc' => r}