mirror of
https://github.com/nushell/nushell
synced 2024-11-15 09:27:08 +00:00
Prevent duplicate records keys when decoding from nuon (#11807)
# Description Fixes #11749: `from nuon` allows duplicate record keys
This commit is contained in:
parent
1bf016bae3
commit
7a181960b7
1 changed files with 12 additions and 4 deletions
|
@ -310,7 +310,8 @@ fn convert_to_value(
|
|||
))
|
||||
}
|
||||
Expr::Record(key_vals) => {
|
||||
let mut record = Record::new();
|
||||
let mut record = Record::with_capacity(key_vals.len());
|
||||
let mut key_spans = Vec::with_capacity(key_vals.len());
|
||||
|
||||
for key_val in key_vals {
|
||||
match key_val {
|
||||
|
@ -327,9 +328,16 @@ fn convert_to_value(
|
|||
}
|
||||
};
|
||||
|
||||
let value = convert_to_value(val, span, original_text)?;
|
||||
|
||||
record.push(key_str, value);
|
||||
if let Some(i) = record.index_of(&key_str) {
|
||||
return Err(ShellError::ColumnDefinedTwice {
|
||||
col_name: key_str,
|
||||
second_use: key.span,
|
||||
first_use: key_spans[i],
|
||||
});
|
||||
} else {
|
||||
key_spans.push(key.span);
|
||||
record.push(key_str, convert_to_value(val, span, original_text)?);
|
||||
}
|
||||
}
|
||||
RecordItem::Spread(_, inner) => {
|
||||
return Err(ShellError::OutsideSpannedLabeledError {
|
||||
|
|
Loading…
Reference in a new issue