mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 20:47:44 +02:00
refactor(nu-command/parse)!: Return null
for unmatched capture groups, rather than empty string (#16094)
Co-authored-by: Bahex <17417311+Bahex@users.noreply.github.com>
This commit is contained in:
@ -78,12 +78,12 @@ impl Command for Parse {
|
|||||||
example: "\"foo! bar.\" | parse --regex '(\\w+)(?=\\.)|(\\w+)(?=!)'",
|
example: "\"foo! bar.\" | parse --regex '(\\w+)(?=\\.)|(\\w+)(?=!)'",
|
||||||
result: Some(Value::test_list(vec![
|
result: Some(Value::test_list(vec![
|
||||||
Value::test_record(record! {
|
Value::test_record(record! {
|
||||||
"capture0" => Value::test_string(""),
|
"capture0" => Value::test_nothing(),
|
||||||
"capture1" => Value::test_string("foo"),
|
"capture1" => Value::test_string("foo"),
|
||||||
}),
|
}),
|
||||||
Value::test_record(record! {
|
Value::test_record(record! {
|
||||||
"capture0" => Value::test_string("bar"),
|
"capture0" => Value::test_string("bar"),
|
||||||
"capture1" => Value::test_string(""),
|
"capture1" => Value::test_nothing(),
|
||||||
}),
|
}),
|
||||||
])),
|
])),
|
||||||
},
|
},
|
||||||
@ -398,8 +398,10 @@ fn captures_to_value(
|
|||||||
.iter()
|
.iter()
|
||||||
.zip(captures.iter().skip(1))
|
.zip(captures.iter().skip(1))
|
||||||
.map(|(column, match_)| {
|
.map(|(column, match_)| {
|
||||||
let match_str = match_.map(|m| m.as_str()).unwrap_or("");
|
let match_value = match_
|
||||||
(column.clone(), Value::string(match_str, span))
|
.map(|m| Value::string(m.as_str(), span))
|
||||||
|
.unwrap_or(Value::nothing(span));
|
||||||
|
(column.clone(), match_value)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user