Don't allow intermixing inline tables and dotted key tables.
This commit is contained in:
parent
e0a820be2f
commit
fad5f4690e
10
src/de.rs
10
src/de.rs
|
@ -526,7 +526,7 @@ impl<'de> de::Deserializer<'de> for ValueDeserializer<'de> {
|
||||||
s.end()?;
|
s.end()?;
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
E::InlineTable(values) => {
|
E::InlineTable(values) | E::DottedTable(values) => {
|
||||||
visitor.visit_map(InlineTableDeserializer {
|
visitor.visit_map(InlineTableDeserializer {
|
||||||
values: values.into_iter(),
|
values: values.into_iter(),
|
||||||
next_value: None,
|
next_value: None,
|
||||||
|
@ -1180,7 +1180,7 @@ impl<'a> Deserializer<'a> {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
match values.iter_mut().find(|&&mut (ref k, _)| *k == key) {
|
match values.iter_mut().find(|&&mut (ref k, _)| *k == key) {
|
||||||
Some(&mut (_, Value { e: E::InlineTable(ref mut v), .. })) => {
|
Some(&mut (_, Value { e: E::DottedTable(ref mut v), .. })) => {
|
||||||
return self.add_dotted_key(key_parts, value, v);
|
return self.add_dotted_key(key_parts, value, v);
|
||||||
}
|
}
|
||||||
Some(&mut (_, Value { start, .. })) => {
|
Some(&mut (_, Value { start, .. })) => {
|
||||||
|
@ -1190,13 +1190,13 @@ impl<'a> Deserializer<'a> {
|
||||||
}
|
}
|
||||||
// The start/end value is somewhat misleading here.
|
// The start/end value is somewhat misleading here.
|
||||||
let inline_table = Value {
|
let inline_table = Value {
|
||||||
e: E::InlineTable(Vec::new()),
|
e: E::DottedTable(Vec::new()),
|
||||||
start: value.start,
|
start: value.start,
|
||||||
end: value.end,
|
end: value.end,
|
||||||
};
|
};
|
||||||
values.push((key, inline_table));
|
values.push((key, inline_table));
|
||||||
let last_i = values.len() - 1;
|
let last_i = values.len() - 1;
|
||||||
if let (_, Value { e: E::InlineTable(ref mut v), .. }) = values[last_i] {
|
if let (_, Value { e: E::DottedTable(ref mut v), .. }) = values[last_i] {
|
||||||
self.add_dotted_key(key_parts, value, v)?;
|
self.add_dotted_key(key_parts, value, v)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1499,6 +1499,7 @@ enum E<'a> {
|
||||||
Datetime(&'a str),
|
Datetime(&'a str),
|
||||||
Array(Vec<Value<'a>>),
|
Array(Vec<Value<'a>>),
|
||||||
InlineTable(Vec<(Cow<'a, str>, Value<'a>)>),
|
InlineTable(Vec<(Cow<'a, str>, Value<'a>)>),
|
||||||
|
DottedTable(Vec<(Cow<'a, str>, Value<'a>)>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Value<'a> {
|
impl<'a> Value<'a> {
|
||||||
|
@ -1511,6 +1512,7 @@ impl<'a> Value<'a> {
|
||||||
(&E::Datetime(..), &E::Datetime(..)) |
|
(&E::Datetime(..), &E::Datetime(..)) |
|
||||||
(&E::Array(..), &E::Array(..)) |
|
(&E::Array(..), &E::Array(..)) |
|
||||||
(&E::InlineTable(..), &E::InlineTable(..)) => true,
|
(&E::InlineTable(..), &E::InlineTable(..)) => true,
|
||||||
|
(&E::DottedTable(..), &E::DottedTable(..)) => true,
|
||||||
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,16 +19,6 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"in": {
|
"in": {
|
||||||
"bar": {
|
|
||||||
"type": "integer",
|
|
||||||
"value": "2"
|
|
||||||
},
|
|
||||||
"foo": {
|
|
||||||
"type": "integer",
|
|
||||||
"value": "1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"in2": {
|
|
||||||
"type": {
|
"type": {
|
||||||
"color": {
|
"color": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
|
|
@ -3,7 +3,5 @@ a.b = 123
|
||||||
[table]
|
[table]
|
||||||
a.b.c = 1
|
a.b.c = 1
|
||||||
a . b . d = 2
|
a . b . d = 2
|
||||||
in = {foo = 1}
|
|
||||||
in.bar = 2
|
|
||||||
|
|
||||||
in2 = { type.name = "cat", type.color = "blue" }
|
in = { type.name = "cat", type.color = "blue" }
|
||||||
|
|
Loading…
Reference in a new issue