quasilyte/phpgrep

Implement Filters for string values (quoted values)

quasilyte opened this issue · 4 comments

Right now quoted values are not supported.

I guess there's a small bug in how filters work. Given the following code,

<?php
define("FOO", "bar");
define('FOO', 'bar');

I tested the following filters using phpgrep example.php 'define($name, $_)' $filter

filter matched
name="FOO" no
name="FOO","BAR" no
name~"FOO" yes
name~^"FOO"$ no
name~^."FOO"$ no
name~^.."FOO".$ yes
name~^\s*"FOO"\s*$ no
name='FOO' no
name='FOO','BAR' no
name~'FOO' yes
name~^'FOO'$ no
name~^.'FOO'$ yes
name~^..'FOO'.$ no
name~^\s*'FOO'\s*$ no

Note that the wildcards needd are different for both quotation marks. I don't know what the wildcards are matching there, but there shouldn't be anything. When using --format '{{.name}}' no extra characters are returned but "FOO" or 'FOO'

Though my issue might be Windows specific? Just noticed this is an issue with non-strings as well

I'm almost sure filters don't work properly on all systems. :)
Thank you for the detailed report.

I'll try to find time to fix filters. It bites me as well from time to time.

Here is the reason why we had such results:
https://github.com/quasilyte/phpgrep/pull/56/files#diff-e4573515329ad01489b20e22a352cd63R83

It was necessary to do a start-1 in the past, with an older php-parser library.
Now it would lead to incorrect result.
I fixed that for the match printing code but filters had their own code path that was left unchanged.

That PR should fix our issues and make filters behave in an expected way.