Skip to content

Commit 97af018

Browse files
committed
---
yaml --- r: 127030 b: refs/heads/snap-stage3 c: dac9a1c h: refs/heads/master v: v3
1 parent 9f3aa34 commit 97af018

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 7be8f0af0393dcdb077c2f6b1653836fd3fba235
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 5bd8edc1121a5736994d69b2dc9cf3efb6fbc116
4+
refs/heads/snap-stage3: dac9a1c5207cb33a0b40813896b74d00bbbd1d36
55
refs/heads/try: 502e4c045236682e9728539dc0d2b3d0b237f55c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libuuid/lib.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,10 @@ impl<T: Encoder<E>, E> Encodable<T, E> for Uuid {
501501
impl<T: Decoder<E>, E> Decodable<T, E> for Uuid {
502502
/// Decode a UUID from a string
503503
fn decode(d: &mut T) -> Result<Uuid, E> {
504-
Ok(from_str(try!(d.read_str()).as_slice()).unwrap())
504+
match from_str(try!(d.read_str()).as_slice()) {
505+
Some(decode) => Ok(decode),
506+
None => Err(d.error("Unable to decode UUID"))
507+
}
505508
}
506509
}
507510

@@ -802,6 +805,23 @@ mod test {
802805
assert_eq!(u, u2);
803806
}
804807

808+
#[test]
809+
fn test_bad_decode() {
810+
use serialize::json;
811+
use serialize::{Encodable, Decodable};
812+
813+
let js_good = json::String("a1a2a3a4a5a6a7a8a1a2a3a4a5a6a7a8".to_string());
814+
let js_bad1 = json::String("a1a2a3a4a5a6a7a8a1a2a3a4a5a6a7ah".to_string());
815+
let js_bad2 = json::String("a1a2a3a4a5a6a7a8a1a2a3a4a5a6a7a".to_string());
816+
817+
let u_good: Result<Uuid, _> = Decodable::decode(&mut json::Decoder::new(js_good));
818+
let u_bad1: Result<Uuid, _> = Decodable::decode(&mut json::Decoder::new(js_bad1));
819+
let u_bad2: Result<Uuid, _> = Decodable::decode(&mut json::Decoder::new(js_bad2));
820+
assert!(u_good.is_ok());
821+
assert!(u_bad1.is_err());
822+
assert!(u_bad2.is_err());
823+
}
824+
805825
#[test]
806826
fn test_iterbytes_impl_for_uuid() {
807827
use std::collections::HashSet;

0 commit comments

Comments
 (0)