Skip to content

Commit 6ae8033

Browse files
authored
Fix ansi strip ignoring the first provided cell path (nushell#16906)
Fixes nushell#13740. `ansi strip` ignored the first provided cell path due to using an invalid starting position when handling rest arguments. See nushell#13740 (comment) for details. ## Release notes summary - What our users need to know <!-- This section will be included as part of our release notes. See the contributing guide for more details. Please include only details relevant for users here. Motivation and technical details can be added above or below this section. You may leave this section blank until your PR is finalized. Ask a core team member if you need help filling this section. --> Fixed `ansi strip` ignoring the first provided cell path.
1 parent e9d1df2 commit 6ae8033

File tree

1 file changed

+24
-6
lines changed
  • crates/nu-command/src/strings/ansi

1 file changed

+24
-6
lines changed

crates/nu-command/src/strings/ansi/strip.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,37 @@ impl Command for AnsiStrip {
5151
call: &Call,
5252
input: PipelineData,
5353
) -> Result<PipelineData, ShellError> {
54-
let cell_paths: Vec<CellPath> = call.rest(engine_state, stack, 1)?;
54+
let cell_paths: Vec<CellPath> = call.rest(engine_state, stack, 0)?;
5555
let cell_paths = (!cell_paths.is_empty()).then_some(cell_paths);
5656
let config = stack.get_config(engine_state);
5757
let args = Arguments { cell_paths, config };
5858
operate(action, args, input, call.head, engine_state.signals())
5959
}
6060

6161
fn examples(&self) -> Vec<Example<'_>> {
62-
vec![Example {
63-
description: "Strip ANSI escape sequences from a string",
64-
example: r#"$'(ansi green)(ansi cursor_on)hello' | ansi strip"#,
65-
result: Some(Value::test_string("hello")),
66-
}]
62+
vec![
63+
Example {
64+
description: "Strip ANSI escape sequences from a string",
65+
example: r#"$'(ansi green)(ansi cursor_on)hello' | ansi strip"#,
66+
result: Some(Value::test_string("hello")),
67+
},
68+
Example {
69+
description: "Strip ANSI escape sequences from a record field",
70+
example: r#"{ greeting: $'hello (ansi red)world' exclamation: false } | ansi strip greeting"#,
71+
result: Some(Value::test_record(record! {
72+
"greeting" => Value::test_string("hello world"),
73+
"exclamation" => Value::test_bool(false)
74+
})),
75+
},
76+
Example {
77+
description: "Strip ANSI escape sequences from multiple table columns",
78+
example: r#"[[language feature]; [$'(ansi red)rust' $'(ansi i)safety']] | ansi strip language feature"#,
79+
result: Some(Value::test_list(vec![Value::test_record(record! {
80+
"language" => Value::test_string("rust"),
81+
"feature" => Value::test_string("safety")
82+
})])),
83+
},
84+
]
6785
}
6886
}
6987

0 commit comments

Comments
 (0)