RUBY-270 support 's' regex option.

Note: Ruby includes dotall 's' semantics on 'm' option.
This commit is contained in:
Kyle Banker 2011-05-09 14:17:56 -04:00
parent 0051b9446a
commit 135bebd9ab
7 changed files with 33 additions and 2 deletions

View File

@ -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;
}

Binary file not shown.

View File

@ -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;
}

View File

@ -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" );

View File

@ -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

View File

@ -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)

View File

@ -396,6 +396,18 @@ class DBAPITest < Test::Unit::TestCase
end
end
def test_regex_multi_line
if @@version >= "1.9.1"
doc = <<HERE
the lazy brown
fox
HERE
@@coll.save({: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.