Skip to content

Commit 419d79f

Browse files
RUST-427 Drop decode_document_utf8_lossy (#172)
1 parent 2f453eb commit 419d79f

File tree

3 files changed

+1
-46
lines changed

3 files changed

+1
-46
lines changed

src/decoder/mod.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -130,28 +130,6 @@ pub fn decode_document<R: Read + ?Sized>(reader: &mut R) -> DecoderResult<Docume
130130
Ok(doc)
131131
}
132132

133-
/// Attempt to decode a `Document` that may contain invalid UTF-8 strings from a byte stream.
134-
pub fn decode_document_utf8_lossy<R: Read + ?Sized>(reader: &mut R) -> DecoderResult<Document> {
135-
let mut doc = Document::new();
136-
137-
// disregard the length: using Read::take causes infinite type recursion
138-
read_i32(reader)?;
139-
140-
loop {
141-
let tag = reader.read_u8()?;
142-
143-
if tag == 0 {
144-
break;
145-
}
146-
147-
let (key, val) = decode_bson_kvp(reader, tag, true)?;
148-
149-
doc.insert(key, val);
150-
}
151-
152-
Ok(doc)
153-
}
154-
155133
fn decode_array<R: Read + ?Sized>(reader: &mut R, utf8_lossy: bool) -> DecoderResult<Array> {
156134
let mut arr = Array::new();
157135

src/lib.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,7 @@ pub use self::{
5353
TimeStamp,
5454
UtcDateTime,
5555
},
56-
decoder::{
57-
decode_document,
58-
decode_document_utf8_lossy,
59-
from_bson,
60-
Decoder,
61-
DecoderError,
62-
DecoderResult,
63-
},
56+
decoder::{decode_document, from_bson, Decoder, DecoderError, DecoderResult},
6457
document::{ValueAccessError, ValueAccessResult},
6558
encoder::{encode_document, to_bson, Encoder, EncoderError, EncoderResult},
6659
};

tests/modules/encoder_decoder.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
use bson::decimal128::Decimal128;
33
use bson::{
44
decode_document,
5-
decode_document_utf8_lossy,
65
doc,
76
encode_document,
87
oid::ObjectId,
@@ -54,21 +53,6 @@ fn test_encode_decode_utf8_string() {
5453
assert_eq!(decoded, doc);
5554
}
5655

57-
#[test]
58-
fn test_encode_decode_utf8_string_invalid() {
59-
let bytes = b"\x80\xae".to_vec();
60-
let src = unsafe { String::from_utf8_unchecked(bytes) };
61-
62-
let doc = doc! { "key": src };
63-
64-
let mut buf = Vec::new();
65-
encode_document(&mut buf, &doc).unwrap();
66-
67-
let expected = doc! { "key": "��" };
68-
let decoded = decode_document_utf8_lossy(&mut Cursor::new(buf)).unwrap();
69-
assert_eq!(decoded, expected);
70-
}
71-
7256
#[test]
7357
fn test_encode_decode_array() {
7458
let src = vec![Bson::FloatingPoint(1.01), Bson::String("xyz".to_owned())];

0 commit comments

Comments
 (0)