Bug in autocomplete in databasejoin plugin - fabrik 3.3.2

fras.marco

New Member
If in the search string the user imputs a "/" character the regex broke. Apache error message:
PHP Warning: preg_match(): Unknown modifier ')' in [joomla folder]/components
/com_fabrik/models/elementlist.php on line 559, referer: [omissis]index.php/home/load-request/form/7/

To resolve, I modified the assignment of the regex in the file /components/com_fabrik/models/elementlist.php, line 546 onwards, BEFORE:
PHP:
                // Search for every word separately in the result rather than the single string (of multiple words)
                $regex  = "/(?=.*" .
                        implode(")(?=.*",
                                array_filter(explode(" ",  addslashes($v)))
                        ) . ").*/i";
AFTER:
PHP:
                // Search for every word separately in the result rather than the single string (of multiple words)
                $regex  = "/(?=.*" .
                        implode(")(?=.*",
                                array_filter(explode(" ", str_replace('/', '\/', addslashes($v))))
                        ) . ").*/i";
The problem is that addslashes doesn't quote the forward slash, so I simply added this quoting.
Steps to reproduce:
Create a list with an element containing strings, populate them with path-like strings, eg:
/usr/bin
/usr/share
in another list create a databasejoin element rendered as autocomplete pointing to that list and try a search string containg a /(eg /usr).

Can this bug be fixed in the next update?
thank you.
Untitled.png
 
Instead of altering the expression itself, can you try doing this, on the line after $regex is assigned:

Code:
$regex = preg_quote($regex, '/');

... which should correctly escape all "special" characters, and (optionally) the delimiter being used:

http://php.net/preg_quote

Let me know.

-- hugh
 
It doesn'nt work, we must not quote the surroundings special chars:
PHP Warning: preg_match(): Delimiter must not be alphanumeric or backslash in ...[omissis]
I tested this and it works:
PHP:
                $regex  = "/(?=.*" .
                        implode(")(?=.*",
                                array_filter(explode(" ",  preg_quote(addslashes($v), '/')))
                        ) . ").*/i";
 
And even better, since we do not need to quote php special chars, remove addslashes():
PHP:
$regex  = "/(?=.*" .
                        implode(")(?=.*",
                                array_filter(explode(" ",  preg_quote($v, '/')))
                        ) . ").*/i";
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top