Skip to content

Commit

Permalink
fix argv param prio
Browse files Browse the repository at this point in the history
 when using --find everything after --find is a grep pattern and
 providing paths after --find will not be interpreted as such.
 this fix checks if a grep pattern is actually a path on the fs
 and moves it to the selected paths instead.
  • Loading branch information
tintinweb committed Mar 7, 2022
1 parent 1945d77 commit 6e9cd38
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions bin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
const cliProgress = require('cli-progress');
const chalk = require('chalk');
const {SolGrep, rules} = require('../src/');
const fs = require('fs');


const argv = require('yargs') // eslint-disable-line
Expand Down Expand Up @@ -87,7 +88,13 @@ function main(){
}

if(argv.find.length){
selectedModules.push(new rules.GenericGrep(undefined, argv.find));
/* bug: argv parser takes everything after --find as grep pattern instead of potential paths.
fix: check if pattern is a path and add it to argv instead
*/
let paths = argv.find.filter(a => fs.existsSync(a));
argv._.push(...paths);

selectedModules.push(new rules.GenericGrep(undefined, argv.find.filter(a => !paths.includes(a))));
}

argv.rule.forEach(r => {
Expand Down Expand Up @@ -146,7 +153,7 @@ function main(){
console.log(" ────────────────────────────")
}
if(argv.output){
require('fs').writeFileSync(argv.output, JSON.stringify(sgrep.findings, null, 2));
fs.writeFileSync(argv.output, JSON.stringify(sgrep.findings, null, 2));
}

sgrep.close();
Expand Down

0 comments on commit 6e9cd38

Please sign in to comment.