mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
Avoid panic when pipe a variable to a custom command which have recursive call (#12491)
# Description Fixes: #11351 And comment here is also fixed: https://github.com/nushell/nushell/issues/11351#issuecomment-1996191537 The panic can happened if we pipe a variable to a custom command which recursively called itself inside another block. TBH, I think I figure out how it works to panic, but I'm not sure if there is a potention issue if nushell don't mutate a block in such case. # User-Facing Changes Nan # Tests + Formatting Done # After Submitting Done --------- Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
22
tests/parsing/samples/recursive_func_with_alias.nu
Normal file
22
tests/parsing/samples/recursive_func_with_alias.nu
Normal file
@ -0,0 +1,22 @@
|
||||
alias "orig update" = update
|
||||
|
||||
# Update a column to have a new value if it exists.
|
||||
#
|
||||
# If the column exists with the value `null` it will be skipped.
|
||||
export def "update" [
|
||||
field: cell-path # The name of the column to maybe update.
|
||||
value: any # The new value to give the cell(s), or a closure to create the value.
|
||||
]: [record -> record, table -> table, list<any> -> list<any>] {
|
||||
let input = $in
|
||||
match ($input | describe | str replace --regex '<.*' '') {
|
||||
record => {
|
||||
if ($input | get -i $field) != null {
|
||||
$input | orig update $field $value
|
||||
} else { $input }
|
||||
}
|
||||
table|list => {
|
||||
$input | each {|| update $field $value }
|
||||
}
|
||||
_ => { $input | orig update $field $value }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user