Just use Regexp#source instead of hacky to_s. Check Regex pattern for NULL bytes

This commit is contained in:
Mike Dirolf 2009-12-17 10:24:58 -05:00
parent 5168692ab9
commit 9bbaafe03d
2 changed files with 8 additions and 2 deletions

View File

@ -451,8 +451,10 @@ class BSON_RUBY
buf.put(REGEX)
self.class.serialize_key(buf, key)
str = val.to_s.sub(/.*?:/, '')[0..-2] # Turn "(?xxx:yyy)" into "yyy"
self.class.serialize_cstr(buf, str)
str = val.source
# We use serialize_key here since regex patterns aren't prefixed with
# length (can't contain the NULL byte).
self.class.serialize_key(buf, str)
options = val.options
options_str = ''

View File

@ -329,6 +329,10 @@ class BSONTest < Test::Unit::TestCase
assert_raise InvalidDocument do
BSON.serialize({"\x00" => "a"})
end
assert_raise InvalidDocument do
BSON.serialize({"a" => (Regexp.compile "ab\x00c")})
end
end
end