Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the bug for "bytes remove --end" . #11428

Merged
merged 3 commits into from
Dec 27, 2023
Merged

Conversation

SebastianIonel
Copy link
Contributor

This PR should close #11426 .

Description

Describe the bug

When using the --end option of bytes remove, nushell panics if the provided bytes don't exist. This doesn't seem to affect bytes remove w/o flag or bytes remove --all.

User-Facing Changes

Nushell doesn`t panic anymore.

Tests + Formatting

Behavior before fixing the bug:
nu-before changes
Behavior after fixing the bug:
nu- after changes

Copy link
Collaborator

@WindSoilder WindSoilder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for your contribution! It'd be good to add a test for such behavior.

I think you can add it to examples

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please add a test for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry, but for the moment, I don't really know how to add a test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SebastianIonel
you should be able to copy-paste one of the Example from

fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Remove contents",
example: "0x[10 AA FF AA FF] | bytes remove 0x[10 AA]",
result: Some(Value::test_binary (
vec![0xFF, 0xAA, 0xFF],
)),
},
Example {
description: "Remove all occurrences of find binary in record field",
example: "{ data: 0x[10 AA 10 BB 10] } | bytes remove --all 0x[10] data",
result: Some(Value::test_record(record! {
"data" => Value::test_binary(vec![0xAA, 0xBB])
})),
},
Example {
description: "Remove occurrences of find binary from end",
example: "0x[10 AA 10 BB CC AA 10] | bytes remove --end 0x[10]",
result: Some(Value::test_binary (
vec![0x10, 0xAA, 0x10, 0xBB, 0xCC, 0xAA],
)),
},
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",
result: Some(Value::test_list (
vec![Value::test_record(record! {
"ColA" => Value::test_binary ( vec![0x12, 0x13],),
"ColB" => Value::test_binary ( vec![0x14, 0x15, 0x16],),
"ColC" => Value::test_binary ( vec![0x17, 0x18, 0x19],),
})],
)),
},
]
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, just need to add something like 0x[10 AA FF] | bytes remove --end 0x[BB]

@fdncred
Copy link
Collaborator

fdncred commented Dec 27, 2023

You could also just add the test @WindSoilder added before closing his PR that does the same thing. https://github.com/nushell/nushell/pull/11427/files

Copy link
Collaborator

@WindSoilder WindSoilder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good to me

@WindSoilder WindSoilder merged commit 15421dc into nushell:main Dec 27, 2023
19 checks passed
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
This PR should close nushell#11426 .

# Description
> ### Describe the bug
> When using the `--end` option of bytes remove, nushell panics if the
provided bytes don't exist. This doesn't seem to affect `bytes remove`
w/o flag or `bytes remove --all`.

# User-Facing Changes
Nushell doesn`t panic anymore.

# Tests + Formatting
Behavior before fixing the bug:
![nu-before
changes](https://github.com/UPB-CS-OpenSourceUpstream/nushell/assets/119429832/f9c26d88-8962-4f38-a373-ba436a26ca7c)
Behavior after fixing the bug:
![nu- after
changes](https://github.com/UPB-CS-OpenSourceUpstream/nushell/assets/119429832/0dd2b487-1696-45a6-9ea2-928cbd3a33a8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bytes remove --end causes panic when specified bytes not present
4 participants