aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2017-02-08 21:36:38 -0800
committerAlex Crichton <alex@alexcrichton.com>2017-02-08 21:36:38 -0800
commit204d1b14e6bd7b67d782def4c4c7837b9045cd8d (patch)
tree7805b214df8707f69dcd9c1daaeb87875a73c825
parent6821911bc7cebac458d2cfb2c14b8d107aa60521 (diff)
downloadmilf-rs-204d1b14e6bd7b67d782def4c4c7837b9045cd8d.tar.gz
milf-rs-204d1b14e6bd7b67d782def4c4c7837b9045cd8d.zip
Implement Deserializer::set_require_newline_after_table
-rw-r--r--src/de.rs32
-rw-r--r--tests/backcompat.rs14
2 files changed, 40 insertions, 6 deletions
diff --git a/src/de.rs b/src/de.rs
index 7cb0410..1406f35 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -581,7 +581,7 @@ impl<'a> Deserializer<'a> {
Deserializer {
tokens: Tokenizer::new(input),
input: input,
- require_newline_after_table: false,
+ require_newline_after_table: true,
}
}
@@ -626,8 +626,22 @@ impl<'a> Deserializer<'a> {
let start = self.tokens.current();
self.expect(Token::LeftBracket)?;
let array = self.eat(Token::LeftBracket)?;
- let ret = Header::new(self.tokens.clone(), array);
- self.tokens.skip_to_newline();
+ let ret = Header::new(self.tokens.clone(),
+ array,
+ self.require_newline_after_table);
+ if self.require_newline_after_table {
+ self.tokens.skip_to_newline();
+ } else {
+ loop {
+ match self.next()? {
+ Some(Token::RightBracket) |
+ Some(Token::Newline) |
+ None => break,
+ _ => {}
+ }
+ }
+ self.eat_whitespace()?;
+ }
Ok(Line::Table { at: start, header: ret, array: array })
}
@@ -1134,15 +1148,19 @@ enum Line<'a> {
struct Header<'a> {
first: bool,
array: bool,
+ require_newline_after_table: bool,
tokens: Tokenizer<'a>,
}
impl<'a> Header<'a> {
- fn new(tokens: Tokenizer<'a>, array: bool) -> Header<'a> {
+ fn new(tokens: Tokenizer<'a>,
+ array: bool,
+ require_newline_after_table: bool) -> Header<'a> {
Header {
first: true,
array: array,
tokens: tokens,
+ require_newline_after_table: require_newline_after_table,
}
}
@@ -1160,8 +1178,10 @@ impl<'a> Header<'a> {
}
self.tokens.eat_whitespace()?;
- if !self.tokens.eat_comment()? {
- self.tokens.eat_newline_or_eof()?;
+ if self.require_newline_after_table {
+ if !self.tokens.eat_comment()? {
+ self.tokens.eat_newline_or_eof()?;
+ }
}
Ok(None)
}
diff --git a/tests/backcompat.rs b/tests/backcompat.rs
new file mode 100644
index 0000000..33dbfa5
--- /dev/null
+++ b/tests/backcompat.rs
@@ -0,0 +1,14 @@
+extern crate toml;
+extern crate serde;
+
+use serde::de::Deserialize;
+
+#[test]
+fn main() {
+ assert!("[a] foo = 1".parse::<toml::Value>().is_err());
+
+ let mut d = toml::de::Deserializer::new("[a] foo = 1");
+ d.set_require_newline_after_table(false);
+ let value = toml::Value::deserialize(&mut d).unwrap();
+ assert_eq!(value["a"]["foo"].as_integer(), Some(1));
+}