phpgrep icon indicating copy to clipboard operation
phpgrep copied to clipboard

Implement Filters for string values (quoted values)

Open quasilyte opened this issue 6 years ago • 4 comments

Right now quoted values are not supported.

quasilyte avatar Jul 25 '19 22:07 quasilyte

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'

JTBrinkmann avatar Sep 10 '20 12:09 JTBrinkmann

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

JTBrinkmann avatar Sep 10 '20 13:09 JTBrinkmann

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.

quasilyte avatar Sep 10 '20 14:09 quasilyte

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.

quasilyte avatar Sep 13 '20 15:09 quasilyte