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

grep: disable regex search for fgrep mode #630

Merged
merged 1 commit into from
May 31, 2024

Conversation

mknos
Copy link
Contributor

@mknos mknos commented May 31, 2024

  • Move regex code for -v flag down to avoid modifying patterns list for fixed-string mode (-F)
  • Fold patterns list to lowercase for -i flag and perform substring match against lc(LINE) with index()
  • For -v mode (negated match), test for index() retval -1
  • Always do quotemeta() on pattern list for fixed-string mode so a quote (') can evaluate correctly in $match_code
  • test1: "perl grep -F alice names" --> no match because my names file had Alice
  • test2: "perl grep -Fi AlIcE names" --> now Alice matches
  • test3: "perl grep -Fv joe names" --> non-joe
  • test4: "perl grep -Fiv JOE names" --> non-joe2, fold case (excludes joe and Joe)
  • test5: "perl grep -F "'" names" --> correctly matches on quote

* Move regex code for -v flag down to avoid modifying patterns list for fixed-string mode (-F)
* Fold patterns list to lowercase for -i flag and perform substring match against lc(LINE) with index()
* For -v mode (negated match), test for index() retval -1
* Always do quotemeta() on pattern list for fixed-string mode so a quote (') can evaluate correctly in $match_code
* test1: "perl grep -F alice names" --> no match because my names file had Alice
* test2: "perl grep -Fi AlIcE names" --> now Alice matches
* test3: "perl grep -Fv joe names" --> non-joe
* test4: "perl grep -Fiv JOE names" --> non-joe2, fold case (excludes joe and Joe)
* test5: "perl grep -F "'" names" --> correctly matches on quote
@github-actions github-actions bot added Type: enhancement improve a feature that already exists Priority: low get to this whenever Program: grep The grep program labels May 31, 2024
@briandfoy
Copy link
Owner

changes: -f (fixed string mode) now disables pattern matching

@briandfoy briandfoy merged commit a9adcbf into briandfoy:master May 31, 2024
2 checks passed
@briandfoy briandfoy added Status: accepted The fix is accepted and removed Priority: low get to this whenever labels May 31, 2024
@briandfoy briandfoy self-assigned this May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Program: grep The grep program Status: accepted The fix is accepted Type: enhancement improve a feature that already exists
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants