From 5152f3aca0b04b74d40799f74f8dcadd0e6acbce Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 31 Mar 2017 18:45:00 -0700 Subject: [PATCH] Fix backcompat with array definitions --- src/de.rs | 7 ++++++- tests/backcompat.rs | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/de.rs b/src/de.rs index 1406f35..1fb2eb5 100644 --- a/src/de.rs +++ b/src/de.rs @@ -634,7 +634,12 @@ impl<'a> Deserializer<'a> { } else { loop { match self.next()? { - Some(Token::RightBracket) | + Some(Token::RightBracket) => { + if array { + self.eat(Token::RightBracket)?; + } + break + } Some(Token::Newline) | None => break, _ => {} diff --git a/tests/backcompat.rs b/tests/backcompat.rs index 33dbfa5..1b3f599 100644 --- a/tests/backcompat.rs +++ b/tests/backcompat.rs @@ -5,10 +5,15 @@ use serde::de::Deserialize; #[test] fn main() { - assert!("[a] foo = 1".parse::().is_err()); + let s = " + [a] foo = 1 + [[b]] foo = 1 + "; + assert!(s.parse::().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); let value = toml::Value::deserialize(&mut d).unwrap(); assert_eq!(value["a"]["foo"].as_integer(), Some(1)); + assert_eq!(value["b"][0]["foo"].as_integer(), Some(1)); }