mirror of
https://github.com/nushell/nushell.git
synced 2025-06-19 17:38:14 +02: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
@ -310,7 +310,8 @@ fn convert_to_value(
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
Expr::Record(key_vals) => {
|
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 {
|
for key_val in key_vals {
|
||||||
match key_val {
|
match key_val {
|
||||||
@ -327,9 +328,16 @@ fn convert_to_value(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let value = convert_to_value(val, span, original_text)?;
|
if let Some(i) = record.index_of(&key_str) {
|
||||||
|
return Err(ShellError::ColumnDefinedTwice {
|
||||||
record.push(key_str, value);
|
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) => {
|
RecordItem::Spread(_, inner) => {
|
||||||
return Err(ShellError::OutsideSpannedLabeledError {
|
return Err(ShellError::OutsideSpannedLabeledError {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user