Skip to content

Commit

Permalink
Tuple deserialization should not fail
Browse files Browse the repository at this point in the history
  • Loading branch information
danburkert committed Nov 1, 2014
1 parent ca6b082 commit 05f6bda
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
10 changes: 6 additions & 4 deletions src/librbml/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,12 @@ pub mod reader {
f: |&mut Decoder<'doc>| -> DecodeResult<T>) -> DecodeResult<T> {
debug!("read_tuple()");
self.read_seq(|d, len| {
assert!(len == tuple_len,
"expected tuple of length `{}`, found tuple \
of length `{}`", tuple_len, len);
f(d)
if len == tuple_len {
f(d)
} else {
Err(Expected(format!("Expected tuple of length `{}`, \
found tuple of length `{}`", tuple_len, len)))
}
})
}

Expand Down
17 changes: 10 additions & 7 deletions src/libserialize/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2153,13 +2153,17 @@ impl ::Decoder<DecoderError> for Decoder {
Ok(value)
}

fn read_tuple<T>(&mut self, tuple_len: uint, f: |&mut Decoder| -> DecodeResult<T>) -> DecodeResult<T> {
fn read_tuple<T>(&mut self,
tuple_len: uint,
f: |&mut Decoder| -> DecodeResult<T>)
-> DecodeResult<T> {
debug!("read_tuple()");
self.read_seq(|d, len| {
assert!(len == tuple_len,
"expected tuple of length `{}`, found tuple \
of length `{}`", tuple_len, len);
f(d)
if len == tuple_len {
f(d)
} else {
Err(ExpectedError(format!("Tuple{}", tuple_len), format!("Tuple{}", len)))
}
})
}

Expand Down Expand Up @@ -2893,9 +2897,8 @@ mod tests {
}

#[test]
#[should_fail]
fn test_decode_tuple_malformed_length() {
let _ = super::decode::<(uint, uint)>("[1, 2, 3]");
assert!(super::decode::<(uint, uint)>("[1, 2, 3]").is_err());
}

#[test]
Expand Down

9 comments on commit 05f6bda

@bors
Copy link
Contributor

@bors bors commented on 05f6bda Nov 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at danburkert@05f6bda

@bors
Copy link
Contributor

@bors bors commented on 05f6bda Nov 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging danburkert/rust/tuple-index-deserialization = 05f6bda into auto

@bors
Copy link
Contributor

@bors bors commented on 05f6bda Nov 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

danburkert/rust/tuple-index-deserialization = 05f6bda merged ok, testing candidate = a6525ca5

@bors
Copy link
Contributor

@bors bors commented on 05f6bda Nov 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 05f6bda Nov 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at danburkert@05f6bda

@bors
Copy link
Contributor

@bors bors commented on 05f6bda Nov 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging danburkert/rust/tuple-index-deserialization = 05f6bda into auto

@bors
Copy link
Contributor

@bors bors commented on 05f6bda Nov 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

danburkert/rust/tuple-index-deserialization = 05f6bda merged ok, testing candidate = 3327ecc

@bors
Copy link
Contributor

@bors bors commented on 05f6bda Nov 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 05f6bda Nov 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 3327ecc

Please sign in to comment.