Fix backcompat with array definitions

This commit is contained in:
Alex Crichton 2017-03-31 18:45:00 -07:00
parent 9880b2518a
commit 5152f3aca0
2 changed files with 13 additions and 3 deletions

View file

@ -634,7 +634,12 @@ impl<'a> Deserializer<'a> {
} else { } else {
loop { loop {
match self.next()? { match self.next()? {
Some(Token::RightBracket) | Some(Token::RightBracket) => {
if array {
self.eat(Token::RightBracket)?;
}
break
}
Some(Token::Newline) | Some(Token::Newline) |
None => break, None => break,
_ => {} _ => {}

View file

@ -5,10 +5,15 @@ use serde::de::Deserialize;
#[test] #[test]
fn main() { fn main() {
assert!("[a] foo = 1".parse::<toml::Value>().is_err()); let s = "
[a] foo = 1
[[b]] foo = 1
";
assert!(s.parse::<toml::Value>().is_err());
let mut d = toml::de::Deserializer::new("[a] foo = 1"); let mut d = toml::de::Deserializer::new(s);
d.set_require_newline_after_table(false); d.set_require_newline_after_table(false);
let value = toml::Value::deserialize(&mut d).unwrap(); let value = toml::Value::deserialize(&mut d).unwrap();
assert_eq!(value["a"]["foo"].as_integer(), Some(1)); assert_eq!(value["a"]["foo"].as_integer(), Some(1));
assert_eq!(value["b"][0]["foo"].as_integer(), Some(1));
} }