Skip to content

Commit

Permalink
Testing Compatibility
Browse files Browse the repository at this point in the history
Also fixing audit task
  • Loading branch information
ecton committed Aug 11, 2024
1 parent 4554256 commit 53cc674
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
File renamed without changes.
23 changes: 8 additions & 15 deletions pot/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,23 +995,16 @@ impl<'a, 's, 'de, R: Reader<'de>> EnumAccess<'de> for &'a mut Deserializer<'s, '
where
V: DeserializeSeed<'de>,
{
// Have the seed deserialize the next atom, which should be the symbol.
// Enum variants that have associated data emit a Named atom followed by
// a mapping of the name and associated data. To parse this, we simply
// need to skip the Named atom.
let atom = self.peek_atom()?;
match atom.kind {
Kind::Special if matches!(atom.nucleus, Some(Nucleus::Named)) => {
self.read_atom()?;
let val = seed.deserialize(&mut *self)?;
Ok((val, self))
}
Kind::Symbol => {
let val = seed.deserialize(&mut *self)?;
Ok((val, self))
}
_ => Err(Error::custom(format!(
"expected Named, got {:?}",
atom.kind
))),
if atom.kind == Kind::Special && matches!(atom.nucleus, Some(Nucleus::Named)) {
self.read_atom()?;
}

let val = seed.deserialize(&mut *self)?;
Ok((val, self))
}
}

Expand Down
36 changes: 36 additions & 0 deletions pot/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,3 +764,39 @@ fn backwards_compatible() {
let parsed: Canary = crate::from_slice(&v1_canary).unwrap();
assert_eq!(canary, parsed);
}

#[test]
fn unit_enum_fix() {
let test_payload = vec![EnumVariants::Unit, EnumVariants::Tuple(0)];
let ambiguous = Config::new()
.compatibility(Compatibility::Full)
.serialize(&test_payload)
.unwrap();
let fixed = Config::new()
.compatibility(Compatibility::V4)
.serialize(&test_payload)
.unwrap();
assert_ne!(ambiguous, fixed);

let bad_value: Value<'_> = crate::from_slice(&ambiguous).unwrap();
let good_value: Value<'_> = crate::from_slice(&fixed).unwrap();
match bad_value {
Value::Sequence(sequence) => {
assert_eq!(sequence[1], Value::None);
}
other => unreachable!("Unexpected value: {other:?}"),
}
match good_value {
Value::Sequence(sequence) => {
assert_eq!(sequence.len(), 2);
assert_eq!(
sequence[1],
Value::Mappings(vec![(
Value::String(Cow::Borrowed("Tuple")),
Value::from(0_u8)
)])
);
}
other => unreachable!("Unexpected value: {other:?}"),
}
}

0 comments on commit 53cc674

Please sign in to comment.