Skip to content

Commit af2344d

Browse files
Merge branch 'main' into typo
2 parents e4d9b43 + e7eb20b commit af2344d

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/strkey.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ mod strkey_decoded_serde_impl {
250250
}
251251
};
252252

253+
if map.next_key::<de::IgnoredAny>()?.is_some() {
254+
return Err(de::Error::custom("expected exactly one variant key"));
255+
}
256+
253257
Ok(Decoded(strkey))
254258
}
255259
}

tests/cli_json.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,19 @@ fn test_roundtrip_claimable_balance() {
152152
let Decoded(deserialized): Decoded<Strkey> = serde_json::from_str(&json).unwrap();
153153
assert_eq!(original, deserialized);
154154
}
155+
156+
#[test]
157+
fn test_extra_variant_keys_rejected() {
158+
let json = r#"{
159+
"public_key_ed25519": "0000000000000000000000000000000000000000000000000000000000000000",
160+
"contract": "0000000000000000000000000000000000000000000000000000000000000000"
161+
}"#;
162+
let err = match serde_json::from_str::<Decoded<Strkey>>(json) {
163+
Ok(_) => panic!("expected error for JSON with extra variant keys"),
164+
Err(e) => e,
165+
};
166+
assert!(
167+
err.to_string().contains("expected exactly one variant key"),
168+
"unexpected error message: {err}",
169+
);
170+
}

0 commit comments

Comments
 (0)