Do not rely on IFS from env when loading combined patterns#197
Do not rely on IFS from env when loading combined patterns#197michaelfindlater wants to merge 4 commits intoawslabs:masterfrom
Conversation
|
Thanks @michaelfindlater! I'm concerned that this may break existing workflows, and may pose some cross-platform incompatibilities. Could you add some tests to verify that (i) this change doesn't regress due to future changes, and (ii) confirm that the behavior is as expected when the IFS separator will work with both standard line ending sequences? ( (Git-secrets uses bats for tests -- there is some general guidance in the README here https://github.com/sstephenson/bats ) |
|
Hi @creswick! Thank you. As requested I have added some tests to help prevent this change regressing in the future. Summary:
I have tested this on macOS, Linux and WSL2. If there's anything I can do further please do not hesitate to ask. |
|
Hello @michaelfindlater I don't know if you also tested it but Windows \r\n are not stripped even if the code says so. Feeding windows git secrets with patterns generated from an unix system - made the thing work. (\n) |
|
@michaelfindlater Test coverage for @amine-bee's failure mode are also needed here, and a fix for whatever failure is produced by having a provider output \r\n-delimited patterns (or a confirmation that it's no longer happening). |
Issue #, if available:
No issue #, but discovered this bug in the course of writing and testing a custom provider.
Regexes seemed to be broken up in a strange way, even when the provider output each correctly on a newline as per the docs (above).
Description of changes:
What?
'\n' rather than default IFS' \t\n'(space, tab, newline)whileinstead offorto avoid modifying/relying on the global value ofIFSWhy?
combined_patterns()concatenates patterns with|for use in a single grep commandExpected
For example, consider the following list of patterns:
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.