Regression since 1.1.1: discard when reading from sequence after error
- Dominant language
- Rust
- Stars
- 1.4k
- Forks
- 162
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I noted a regression when using rmp_serde 1.2.0 and over, when trying to read from a deserializer that had an error
consider the following script:
```rust
use std::fmt;
use rmp_serde;
use serde::Deserialize;
use serde::de::{Deserializer, Visitor};
// a sample struct that expects an array with one i8 at the end
// to simulate error recovery
struct ContinueTillI8(i8);
impl<'de> Deserialize<'de> for ContinueTillI8 {
fn deserialize(deserializer: D) -> Result
where
D: Deserializer<'de>,
{
struct ContinueTillI8Visitor;
impl<'de> Visitor<'de> for ContinueTillI8Visitor {
type Value = ContinueTillI8;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("array that has one i8 at the end")
}
deserializer.deserialize_any(ContinueTillI8Visitor)
}
}
fn main(){
let data = ("hi", 8);
let raw_data = rmp_serde::to_vec(&data).unwrap();
let value: ContinueTillI8 = rmp_serde::from_slice(&raw_data[..]).unwrap();
println!("{:?}", value.0); // should print 8
}
```
with rmp_serde 1.2.0 and up, I get the following result:
```
discarded element with err: TypeMismatch(FixStr(2))
104
```
with 1.1.1, we get the expected output of 8
```
discarded element with err: Syntax("invalid type: string \"hi\", expected i8")
8
```
this is likely due to rmp_serde not consuming the `FixStr(2)`'s actual value after detecting it is not an i8, leaving the deserailizer in an invalid state
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.