diff --git a/crates/nu-command/src/bytes/remove.rs b/crates/nu-command/src/bytes/remove.rs index 458e75c42e..b89b0c8879 100644 --- a/crates/nu-command/src/bytes/remove.rs +++ b/crates/nu-command/src/bytes/remove.rs @@ -105,6 +105,13 @@ impl Command for BytesRemove { vec![0x10, 0xAA, 0x10, 0xBB, 0xCC, 0xAA], )), }, + Example { + description: "Remove find binary from end not found", + example: "0x[10 AA 10 BB CC AA 10] | bytes remove --end 0x[11]", + result: Some(Value::test_binary ( + vec![0x10, 0xAA, 0x10, 0xBB, 0xCC, 0xAA, 0x10], + )), + }, Example { description: "Remove all occurrences of find binary in table", example: "[[ColA ColB ColC]; [0x[11 12 13] 0x[14 15 16] 0x[17 18 19]]] | bytes remove 0x[11] ColA ColC", @@ -159,8 +166,11 @@ fn remove_impl(input: &[u8], arg: &Arguments, span: Span) -> Value { } // append the remaining thing to result, this can be happening when // we have something to remove and remove_all is False. - let mut remain = input[..left as usize].iter().copied().rev().collect(); - result.append(&mut remain); + // check if the left is positive, if it is not, we don't need to append anything. + if left > 0 { + let mut remain = input[..left as usize].iter().copied().rev().collect(); + result.append(&mut remain); + } result = result.into_iter().rev().collect(); Value::binary(result, span) } else {