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) { if (flags & MULTILINE) {
char multiline = 'm'; char multiline = 'm';
char dotall = 's';
SAFE_WRITE(buffer, &multiline, 1); SAFE_WRITE(buffer, &multiline, 1);
SAFE_WRITE(buffer, &dotall, 1);
} }
if (flags & EXTENDED) { if (flags & EXTENDED) {
char extended = 'x'; char extended = 'x';
@ -759,6 +761,9 @@ static VALUE get_value(const char* buffer, int* position, int type) {
else if (flag == 'm') { else if (flag == 'm') {
flags |= MULTILINE; flags |= MULTILINE;
} }
else if (flag == 's') {
flags |= MULTILINE;
}
else if (flag == 'x') { else if (flag == 'x') {
flags |= EXTENDED; flags |= EXTENDED;
} }

Binary file not shown.

View File

@ -234,6 +234,9 @@ public class RubyBSONCallback implements BSONCallback {
if(flags.contains("m")) { if(flags.contains("m")) {
f = f | ReOptions.RE_OPTION_MULTILINE; f = f | ReOptions.RE_OPTION_MULTILINE;
} }
if(flags.contains("s")) {
f = f | ReOptions.RE_OPTION_MULTILINE;
}
if(flags.contains("x")) { if(flags.contains("x")) {
f = f | ReOptions.RE_OPTION_EXTENDED; f = f | ReOptions.RE_OPTION_EXTENDED;
} }

View File

@ -642,8 +642,10 @@ public class RubyBSONEncoder extends BSONEncoder {
if( (regexOptions & ReOptions.RE_OPTION_IGNORECASE) != 0 ) if( (regexOptions & ReOptions.RE_OPTION_IGNORECASE) != 0 )
options = options.concat( "i" ); 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( "m" );
options = options.concat( "s" );
}
if( (regexOptions & ReOptions.RE_OPTION_EXTENDED) != 0 ) if( (regexOptions & ReOptions.RE_OPTION_EXTENDED) != 0 )
options = options.concat( "x" ); options = options.concat( "x" );

View File

@ -343,6 +343,7 @@ module BSON
opts = 0 opts = 0
opts |= Regexp::IGNORECASE if options_str.include?('i') opts |= Regexp::IGNORECASE if options_str.include?('i')
opts |= Regexp::MULTILINE if options_str.include?('m') opts |= Regexp::MULTILINE if options_str.include?('m')
opts |= Regexp::MULTILINE if options_str.include?('s')
opts |= Regexp::EXTENDED if options_str.include?('x') opts |= Regexp::EXTENDED if options_str.include?('x')
Regexp.new(str, opts) Regexp.new(str, opts)
end end
@ -500,7 +501,10 @@ module BSON
options = val.options options = val.options
options_str = '' options_str = ''
options_str << 'i' if ((options & Regexp::IGNORECASE) != 0) 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 << 'x' if ((options & Regexp::EXTENDED) != 0)
options_str << val.extra_options_str if val.respond_to?(:extra_options_str) options_str << val.extra_options_str if val.respond_to?(:extra_options_str)
# Must store option chars in alphabetical order # Must store option chars in alphabetical order

View File

@ -245,6 +245,11 @@ class BSONTest < Test::Unit::TestCase
assert_doc_pass(doc) assert_doc_pass(doc)
end end
def test_regex_multiline
doc = {'doc' => /foobar/m}
assert_doc_pass(doc)
end
def test_boolean def test_boolean
doc = {'doc' => true} doc = {'doc' => true}
assert_doc_pass(doc) assert_doc_pass(doc)

View File

@ -396,6 +396,18 @@ class DBAPITest < Test::Unit::TestCase
end end
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 def test_non_oid_id
# Note: can't use Time.new because that will include fractional seconds, # Note: can't use Time.new because that will include fractional seconds,
# which Mongo does not store. # which Mongo does not store.