mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 09:55:42 +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+)(?=!)'",
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_record(record! {
|
||||
"capture0" => Value::test_string(""),
|
||||
"capture0" => Value::test_nothing(),
|
||||
"capture1" => Value::test_string("foo"),
|
||||
}),
|
||||
Value::test_record(record! {
|
||||
"capture0" => Value::test_string("bar"),
|
||||
"capture1" => Value::test_string(""),
|
||||
"capture1" => Value::test_nothing(),
|
||||
}),
|
||||
])),
|
||||
},
|
||||
@ -398,8 +398,10 @@ fn captures_to_value(
|
||||
.iter()
|
||||
.zip(captures.iter().skip(1))
|
||||
.map(|(column, match_)| {
|
||||
let match_str = match_.map(|m| m.as_str()).unwrap_or("");
|
||||
(column.clone(), Value::string(match_str, span))
|
||||
let match_value = match_
|
||||
.map(|m| Value::string(m.as_str(), span))
|
||||
.unwrap_or(Value::nothing(span));
|
||||
(column.clone(), match_value)
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
Reference in New Issue
Block a user