mirror of
https://github.com/nushell/nushell.git
synced 2025-07-07 18:07:02 +02:00
handle empty pipeline while parsing let (fix Issue10083) (#10116)
- fixes #10083 # Description nushell crashes in the following 2 condition: - `let a = {}` , then delete `{` - `let a = | {}`, then delete `{` When delete `{` the pipeline becomes empty but current `nu-parser` assume they are non-empty. This pr adds extra empty check to avoid crash. Co-authored-by: Horasal <horsal@horsal.dev>
This commit is contained in:
@ -5476,10 +5476,14 @@ pub fn parse_pipeline(
|
||||
{
|
||||
let block = working_set.get_block(*block_id);
|
||||
|
||||
let element = block.pipelines[0].elements[0].clone();
|
||||
|
||||
if let PipelineElement::Expression(prepend, expr) =
|
||||
element
|
||||
if let Some(PipelineElement::Expression(
|
||||
prepend,
|
||||
expr,
|
||||
)) = block
|
||||
.pipelines
|
||||
.first()
|
||||
.and_then(|p| p.elements.first())
|
||||
.cloned()
|
||||
{
|
||||
if expr.has_in_variable(working_set) {
|
||||
let new_expr = PipelineElement::Expression(
|
||||
@ -5608,9 +5612,12 @@ pub fn parse_pipeline(
|
||||
{
|
||||
let block = working_set.get_block(*block_id);
|
||||
|
||||
let element = block.pipelines[0].elements[0].clone();
|
||||
|
||||
if let PipelineElement::Expression(prepend, expr) = element {
|
||||
if let Some(PipelineElement::Expression(prepend, expr)) = block
|
||||
.pipelines
|
||||
.first()
|
||||
.and_then(|p| p.elements.first())
|
||||
.cloned()
|
||||
{
|
||||
if expr.has_in_variable(working_set) {
|
||||
let new_expr = PipelineElement::Expression(
|
||||
prepend,
|
||||
|
Reference in New Issue
Block a user