File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments