-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnexpectedEof
error on 0.28.
#580
Comments
Thanks for report. I've seen the same error when investigating #567, so probably the cause is the same. It would be wonderful if you'll try to minify your example and do bisect between versions to find the exact commit where the bug was introduced. The history is mostly linear and mostly each commit contains working state, so this shouldn't be too hard. The error is definitely related to sequence deserialization. |
About simplifying, this is maximum what I can do: [package]
name = "playground"
version = "0.1.0"
edition = "2021"
[dependencies]
#OK
#quick-xml = { git = "https://github.com/tafia/quick-xml.git", rev = "b3ebf7a038f3984803589eb19aaaf4e950bf68b3", features = ["serialize", "overlapped-lists"] }
#Not OK
quick-xml = { git = "https://github.com/tafia/quick-xml.git", rev = "221b57d73f9f44060bcf13f49e5868ee13ae1f55", features = ["serialize", "overlapped-lists"] } use quick_xml::de::from_str;
use serde::{Deserialize, Deserializer};
use std::{error::Error, fmt::Debug};
trait XmlParser {
fn parse<'de, D>(deserializer: D) -> Result<Self, D::Error>
where
Self: Sized,
D: Deserializer<'de>;
}
#[derive(Debug, Deserialize)]
pub struct Seq {
#[serde(rename = "$value", deserialize_with = "XmlParser::parse")]
pub new_ids: Vec<Bar>,
}
#[derive(Debug)]
pub struct Bar {
pub id: u32,
pub num: u32,
}
impl XmlParser for Bar {
fn parse<'de, D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
#[allow(clippy::enum_variant_names)]
#[derive(Copy, Clone, Deserialize)]
enum _Bar {
One(NewId),
Two(NewId),
}
#[derive(Copy, Clone, Deserialize)]
struct NewId {
#[serde(rename = "@newID")]
id: u32,
}
let (id, num) = match _Bar::deserialize(deserializer)? {
_Bar::One(NewId { id }) => (id, 1),
_Bar::Two(NewId { id }) => (id, 2),
};
Ok(Bar { id, num })
}
}
// TODO: https://github.com/serde-rs/serde/issues/723
impl<T> XmlParser for Vec<T>
where
T: XmlParser,
{
fn parse<'de, D>(deserializer: D) -> Result<Self, D::Error>
where
Self: Sized,
D: Deserializer<'de>,
{
#[derive(Deserialize)]
struct _T<T: XmlParser>(#[serde(deserialize_with = "XmlParser::parse")] T);
let arr = Vec::deserialize(deserializer)?
.into_iter()
.map(|_T(t)| t)
.collect();
Ok(arr)
}
}
fn main() -> Result<(), Box<dyn Error>> {
const XML: &str = r#"
<Seq>
<One newID="10" />
<Two newID="20" />
</Seq>"#;
println!("{:?}", from_str::<Seq>(XML)?);
Ok(())
} |
any updates on this? |
I just start to use different approach. |
The minimal reproduction case is /// Regression test for https://github.com/tafia/quick-xml/issues/580.
#[test]
fn issue580() {
#[derive(Debug, Deserialize, PartialEq, Eq)]
struct Seq {
#[serde(rename = "$value")]
items: Vec<Wrapper>,
}
#[derive(Debug, Deserialize, PartialEq, Eq)]
struct Wrapper(#[serde(deserialize_with = "Item::parse")] Item);
#[derive(Debug, PartialEq, Eq)]
struct Item;
impl Item {
fn parse<'de, D>(_deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
Ok(Item)
}
}
assert_eq!(
from_str::<Seq>(
r#"
<Seq>
<One/>
<Two/>
</Seq>"#
)
.unwrap(),
Seq {
items: vec![Wrapper(Item), Wrapper(Item)]
}
);
} If replace vector item type from |
---- issue580 stdout ---- thread 'issue580' panicked at tests/serde-issues.rs:412:10: called `Result::unwrap()` on an `Err` value: Custom("invalid length 0, expected tuple struct Wrapper with 1 element") note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace failures: issue580
…ct instead of visit_seq The problem was in `SeqItemDeserializer::deserialize_newtype_struct`. Previously it was the same as `SeqItemDeserializer::deserialize_seq`, but deserializing sequences in this deserializer assumes, that those sequences are `xs:list`s, because deserializer itself represents a list element. In the original bug report an `UnexpectedEof` is returning. The error was changed in the pre-previous commit (3d5ed69) and in this it is fixed. The following tests checks that all's OK: - Deserializer::deserialize_newtype_struct is reached by: - serde-de: - newtype::excess_attribute - newtype::simple - serde-se: - with_root::newtype - without_root::newtype - MapValueDeserializer::deserialize_newtype_struct is reached by: - serde-issues: - issue343 - SeqItemDeserializer::deserialize_newtype_struct is reached by: - serde-issues: - issue580
Greeting!
Start getting error on 0.28 version (0.27 work fine).
Here example to reproduce error:
P.S.
XmlParser
trait needed because I need also json serialization / deserialization.The text was updated successfully, but these errors were encountered: