Error when deserializing invalid hex (#2339)
Conflicts: rpc/src/v1/types/bytes.rs
This commit is contained in:
		
							parent
							
								
									09210269c9
								
							
						
					
					
						commit
						2135ba467c
					
				| @ -77,9 +77,9 @@ impl Visitor for BytesVisitor { | ||||
| 			); | ||||
| 			Ok(Bytes::new(Vec::new())) | ||||
| 		} else if value.len() >= 2 && &value[0..2] == "0x" && value.len() & 1 == 0 { | ||||
| 			Ok(Bytes::new(FromHex::from_hex(&value[2..]).unwrap_or_else(|_| vec![]))) | ||||
| 			Ok(Bytes::new(try!(FromHex::from_hex(&value[2..]).map_err(|_| Error::custom("invalid hex"))))) | ||||
| 		} else { | ||||
| 			Err(Error::custom("invalid hex")) | ||||
| 			Err(Error::custom("invalid format")) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| @ -107,16 +107,18 @@ mod tests { | ||||
| 		// TODO [ToDr] Uncomment when Mist starts sending correct data
 | ||||
| 		// let bytes1: Result<Bytes, serde_json::Error> = serde_json::from_str(r#""""#);
 | ||||
| 		let bytes2: Result<Bytes, serde_json::Error> = serde_json::from_str(r#""0x123""#); | ||||
| 		let bytes3: Result<Bytes, serde_json::Error> = serde_json::from_str(r#""0xgg""#); | ||||
| 
 | ||||
| 		let bytes3: Bytes = serde_json::from_str(r#""0x""#).unwrap(); | ||||
| 		let bytes4: Bytes = serde_json::from_str(r#""0x12""#).unwrap(); | ||||
| 		let bytes5: Bytes = serde_json::from_str(r#""0x0123""#).unwrap(); | ||||
| 		let bytes4: Bytes = serde_json::from_str(r#""0x""#).unwrap(); | ||||
| 		let bytes5: Bytes = serde_json::from_str(r#""0x12""#).unwrap(); | ||||
| 		let bytes6: Bytes = serde_json::from_str(r#""0x0123""#).unwrap(); | ||||
| 
 | ||||
| 		// assert!(bytes1.is_err());
 | ||||
| 		assert!(bytes2.is_err()); | ||||
| 		assert_eq!(bytes3, Bytes(vec![])); | ||||
| 		assert_eq!(bytes4, Bytes(vec![0x12])); | ||||
| 		assert_eq!(bytes5, Bytes(vec![0x1, 0x23])); | ||||
| 		assert!(bytes3.is_err()); | ||||
| 		assert_eq!(bytes4, Bytes(vec![])); | ||||
| 		assert_eq!(bytes5, Bytes(vec![0x12])); | ||||
| 		assert_eq!(bytes6, Bytes(vec![0x1, 0x23])); | ||||
| 	} | ||||
| 
 | ||||
| 	// TODO [ToDr] Remove when Mist starts sending correct data
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user