diff --git a/ext/cbson/cbson.c b/ext/cbson/cbson.c index e75a56e..17cd4e7 100644 --- a/ext/cbson/cbson.c +++ b/ext/cbson/cbson.c @@ -495,7 +495,9 @@ static int write_element(VALUE key, VALUE value, VALUE extra, int allow_id) { } if (flags & MULTILINE) { char multiline = 'm'; + char dotall = 's'; SAFE_WRITE(buffer, &multiline, 1); + SAFE_WRITE(buffer, &dotall, 1); } if (flags & EXTENDED) { char extended = 'x'; @@ -759,6 +761,9 @@ static VALUE get_value(const char* buffer, int* position, int type) { else if (flag == 'm') { flags |= MULTILINE; } + else if (flag == 's') { + flags |= MULTILINE; + } else if (flag == 'x') { flags |= EXTENDED; } diff --git a/ext/java/jar/jbson.jar b/ext/java/jar/jbson.jar index dc5a7d8..61d1916 100644 Binary files a/ext/java/jar/jbson.jar and b/ext/java/jar/jbson.jar differ diff --git a/ext/java/src/org/jbson/RubyBSONCallback.java b/ext/java/src/org/jbson/RubyBSONCallback.java index b20ec2c..ed70640 100644 --- a/ext/java/src/org/jbson/RubyBSONCallback.java +++ b/ext/java/src/org/jbson/RubyBSONCallback.java @@ -234,6 +234,9 @@ public class RubyBSONCallback implements BSONCallback { if(flags.contains("m")) { f = f | ReOptions.RE_OPTION_MULTILINE; } + if(flags.contains("s")) { + f = f | ReOptions.RE_OPTION_MULTILINE; + } if(flags.contains("x")) { f = f | ReOptions.RE_OPTION_EXTENDED; } diff --git a/ext/java/src/org/jbson/RubyBSONEncoder.java b/ext/java/src/org/jbson/RubyBSONEncoder.java index 5b63be9..e7f8b79 100644 --- a/ext/java/src/org/jbson/RubyBSONEncoder.java +++ b/ext/java/src/org/jbson/RubyBSONEncoder.java @@ -642,8 +642,10 @@ public class RubyBSONEncoder extends BSONEncoder { if( (regexOptions & ReOptions.RE_OPTION_IGNORECASE) != 0 ) options = options.concat( "i" ); - if( (regexOptions & ReOptions.RE_OPTION_MULTILINE) != 0 ) + if( (regexOptions & ReOptions.RE_OPTION_MULTILINE) != 0 ) { options = options.concat( "m" ); + options = options.concat( "s" ); + } if( (regexOptions & ReOptions.RE_OPTION_EXTENDED) != 0 ) options = options.concat( "x" ); diff --git a/lib/bson/bson_ruby.rb b/lib/bson/bson_ruby.rb index de3440f..de7bff0 100644 --- a/lib/bson/bson_ruby.rb +++ b/lib/bson/bson_ruby.rb @@ -343,6 +343,7 @@ module BSON opts = 0 opts |= Regexp::IGNORECASE if options_str.include?('i') opts |= Regexp::MULTILINE if options_str.include?('m') + opts |= Regexp::MULTILINE if options_str.include?('s') opts |= Regexp::EXTENDED if options_str.include?('x') Regexp.new(str, opts) end @@ -500,7 +501,10 @@ module BSON options = val.options options_str = '' options_str << 'i' if ((options & Regexp::IGNORECASE) != 0) - options_str << 'm' if ((options & Regexp::MULTILINE) != 0) + if ((options & Regexp::MULTILINE) != 0) + options_str << 'm' + options_str << 's' + end options_str << 'x' if ((options & Regexp::EXTENDED) != 0) options_str << val.extra_options_str if val.respond_to?(:extra_options_str) # Must store option chars in alphabetical order diff --git a/test/bson/bson_test.rb b/test/bson/bson_test.rb index 27dff22..fe2d097 100644 --- a/test/bson/bson_test.rb +++ b/test/bson/bson_test.rb @@ -245,6 +245,11 @@ class BSONTest < Test::Unit::TestCase assert_doc_pass(doc) end + def test_regex_multiline + doc = {'doc' => /foobar/m} + assert_doc_pass(doc) + end + def test_boolean doc = {'doc' => true} assert_doc_pass(doc) diff --git a/test/db_api_test.rb b/test/db_api_test.rb index 1bb5b9c..da48803 100644 --- a/test/db_api_test.rb +++ b/test/db_api_test.rb @@ -396,6 +396,18 @@ class DBAPITest < Test::Unit::TestCase end end + def test_regex_multi_line + if @@version >= "1.9.1" +doc = < doc}) + assert @@coll.find_one({:doc => /n.*x/m}) + @@coll.remove + end + end + def test_non_oid_id # Note: can't use Time.new because that will include fractional seconds, # which Mongo does not store.