phpgrep
phpgrep copied to clipboard
How to match backticks `...` or eval()
How to match ls -al
fragment in code like:
$output = ls -al
;
Related to this - is there a way to match PHP language constructs?
For the source code like:
<?php
eval("echo 123");
This will not return any match:
phpgrep eval_test.php 'eval(${"*"})'
I'll take a look today.
If it doesn't match eval
, it's probably easy to fix.
Backticks, on the other hand, need more thoughts.
We can introduce ${"exec"}
pseudo-node in addition to ${"str"}
, so you can match exec with any content.
Right now you can use matcher var filter:
phpgrep hello.php '${"x:expr"}' 'x~^`.*`$'
hello.php:2: `ls .`
hello.php:3: `echo 123`
We match all expressions then check that they start with ` and end with a same character.
hello.php:
<?php
$v = `ls .`;
`echo 123`;
echo 123;
That actually works for me just fine - thanks for the hint!
I also noticed that your initial question was asked on the 25th of September. For some reason, I haven't noticed it until the recent update. Sorry for the late response.
I think eval
is properly handled now, there is even a test case for it. :)
$ phpgrep hello.php 'eval($x)'
hello.php:3: eval('123')
hello.php:5: eval('$x = 1')
$ cat hello.php
<?php
eval('123');
function f() {
eval('$x = 1');
}
Oh, ${"*"}
is not handled properly inside of eval, now I see it.
Try using eval($_)
or eval($x)
, since it only accepts at most argument.