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

cut: better input validation for -b and -f #403

Merged
merged 1 commit into from
Jan 9, 2024

Conversation

mknos
Copy link
Contributor

@mknos mknos commented Jan 9, 2024

  • Options -b and -f are consistent in how the value is handled
  • Byte and field numbers count from 1
  • Negative numbers are treated as a range end, with range starting from 1
  • Regular ranges have 2 numbers separated by '-'
  • Introduce a number validation function
  • test1: positive -b value: "echo 'a:b:c:d' | perl cut -b 3" --> byte 3 is "b"
  • test2: negative -b value: "echo 'a:b:c:d' | perl cut -b -3" --> bytes 1-3 are "a:b"
  • test3: -b range: "echo 'a:b:c:d' | perl cut -b 2-3" --> bytes 2-3 are ":b"
  • test4: positive -f value: "echo 'a:b:c:d' | perl cut -d ':' -f 2" --> field 2 is "b"
  • test5: negative -f value: "echo 'a:b:c:d' | perl cut -d ':' -f -2" --> fields 1-2 are "a:b"
  • test6: -f range: "echo 'a:b:c:d' | perl cut -d ':' -f 2-3" --> fields 2-3 are "b:c"

* Options -b and -f are consistent in how the value is handled
* Byte and field numbers count from 1
* Negative numbers are treated as a range end, with range starting from 1
* Regular ranges have 2 numbers separated by '-'
* Introduce a number validation function
* test1: positive -b value: "echo 'a:b:c:d' | perl cut -b 3" --> byte 3 is "b"
* test2: negative -b value: "echo 'a:b:c:d' | perl cut -b -3" --> bytes 1-3 are "a:b"
* test3: -b range: "echo 'a:b:c:d' | perl cut -b 2-3" --> bytes 2-3 are ":b"
* test4: positive -f value: "echo 'a:b:c:d' | perl cut -d ':' -f 2" --> field 2 is "b"
* test5: negative -f value: "echo 'a:b:c:d' | perl cut -d ':' -f -2" --> fields 1-2 are "a:b"
* test6: -f range: "echo 'a:b:c:d' | perl cut -d ':' -f 2-3" --> fields 2-3 are "b:c"
@mknos mknos changed the title title: better input validation for -b and -f cut: better input validation for -b and -f Jan 9, 2024
@github-actions github-actions bot added Type: enhancement improve a feature that already exists Priority: low get to this whenever Program: cut The cut program labels Jan 9, 2024
@briandfoy briandfoy self-assigned this Jan 9, 2024
Copy link
Owner

@briandfoy briandfoy left a comment

Choose a reason for hiding this comment

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

I think there are a few formatting things to fix up, but I'll take care of that. Maybe it's just the GitHub display of the diff.

@briandfoy briandfoy merged commit 24bbbff into briandfoy:master Jan 9, 2024
2 checks passed
@briandfoy briandfoy added Status: accepted The fix is accepted and removed Priority: low get to this whenever labels Jan 9, 2024
briandfoy added a commit that referenced this pull request Jan 9, 2024
@briandfoy briandfoy added Status: released there is a new release with this fix and removed Status: accepted The fix is accepted labels Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Program: cut The cut program Status: released there is a new release with this fix Type: enhancement improve a feature that already exists
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants