Test for null bytes in bson string

Make sure there is no regression in the C driver for:

https://jira.mongodb.org/browse/CDRIVER-2250
pull/32/head
Thijs Cadier 7 years ago
parent c3c364c059
commit 9cdd8e7b62

@ -36,6 +36,8 @@ pub enum InsertFlag {
NoValidate NoValidate
} }
const INSERT_FLAG_NO_VALIDATE: u32 = 1 | 31; // MONGOC_INSERT_NO_VALIDATE defined in macro
impl FlagsValue for Flags<InsertFlag> { impl FlagsValue for Flags<InsertFlag> {
fn flags(&self) -> u32 { fn flags(&self) -> u32 {
if self.flags.is_empty() { if self.flags.is_empty() {
@ -44,7 +46,7 @@ impl FlagsValue for Flags<InsertFlag> {
self.flags.iter().fold(0, { |flags, flag| self.flags.iter().fold(0, { |flags, flag|
flags | match flag { flags | match flag {
&InsertFlag::ContinueOnError => bindings::MONGOC_INSERT_CONTINUE_ON_ERROR, &InsertFlag::ContinueOnError => bindings::MONGOC_INSERT_CONTINUE_ON_ERROR,
&InsertFlag::NoValidate => 1 | 31 // MONGOC_INSERT_NO_VALIDATE defined in macro &InsertFlag::NoValidate => INSERT_FLAG_NO_VALIDATE
} }
}) })
} }

@ -72,9 +72,9 @@ fn test_mutation_and_finding() {
let document = doc! { let document = doc! {
"key_1" => "Value 1", "key_1" => "Value 1",
"key_2" => "kācaṃ śaknomyattum; nopahinasti mām." "key_2" => "kācaṃ śaknomyattum; nopahinasti mām. \u{0}"
}; };
assert!(collection.insert(&document, None).is_ok()); collection.insert(&document, None).expect("Could not insert document");
{ {
let found_document = collection.find(&document, None).unwrap().next().unwrap().unwrap(); let found_document = collection.find(&document, None).unwrap().next().unwrap().unwrap();
assert_eq!( assert_eq!(
@ -83,7 +83,7 @@ fn test_mutation_and_finding() {
); );
assert_eq!( assert_eq!(
found_document.get("key_2").unwrap(), found_document.get("key_2").unwrap(),
&bson::Bson::String("kācaṃ śaknomyattum; nopahinasti mām.".to_string()) &bson::Bson::String("kācaṃ śaknomyattum; nopahinasti mām. \u{0}".to_string())
); );
} }

Loading…
Cancel
Save