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

Do not rely on IFS from env when loading combined patterns #4

Merged
merged 1 commit into from
Jul 19, 2021

Conversation

michaelfindlater
Copy link
Collaborator

@michaelfindlater michaelfindlater commented Jul 15, 2021

What?

  • load patterns delimited by '\n' rather than default IFS ' \t\n' (space, tab, newline)
  • use while instead of for to avoid modifying/relying on the global value of IFS (general best practice)
  • PR also opened on the awslabs/git-secrets side

Why?

  • combined_patterns() concatenates patterns with | for use in a single grep command
  • using the default value of IFS means patterns containing a space character delimited by space, rather than newline
  • this causes unexpected behavior (false matches from words split by space)

Expected

For example, consider the following list of patterns:

^my-regex$
^my regex with spaces$

load_combined_patterns() should transform them into: ^my-regex$|^my regex with spaces$

Actual

The above example ends up as ^my-regex$|^my|regex|with|spaces$.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@michaelfindlater michaelfindlater changed the title Do not rely on IFS from env Do not rely on IFS from env when loading combined patterns Jul 15, 2021
@michaelfindlater michaelfindlater requested a review from nessex July 15, 2021 07:03
@michaelfindlater michaelfindlater self-assigned this Jul 15, 2021
@michaelfindlater michaelfindlater added the bug Something isn't working label Jul 15, 2021
Copy link

@tomoyat1 tomoyat1 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@michaelfindlater michaelfindlater merged commit ff05bba into master Jul 19, 2021
@michaelfindlater michaelfindlater deleted the fix-combined-patterns-loader branch July 19, 2021 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants