Verified Commit fb35a648 authored by dockx thibault's avatar dockx thibault
Browse files

:ambulance: (filter) - modify filtering logic

Adapts filtering to php8.2
No related merge requests found
Showing with 31 additions and 13 deletions
+31 -13
......@@ -138,34 +138,52 @@ class ldapFilterLeaf extends ldapFilter implements \Stringable
protected $pattern;
protected $dnFilter = FALSE;
function __construct ($left, $operator, $right)
function __construct($left, $operator, $right)
{
if (@strrpos((string) $left, ':dn:', -4) !== FALSE) {
$this->dnFilter = TRUE;
$left = substr((string) $left, 0, -4);
// Ensure $left is a string for consistency
$left = (string) $left;
// Check if $left ends with ':dn:' using str_ends_with()
if (str_ends_with($left, ':dn:')) {
$this->dnFilter = true;
$left = substr($left, 0, -4); // Remove ':dn:'
}
parent::__construct($operator, [$left, $right]);
if (($this->operator == '=') || ($this->operator == '~=')) {
if ($this->operator === '=' || $this->operator === '~=') {
$prefix = '';
$suffix = '';
if (preg_match('/^\\*/', (string) $this->subparts[1])) {
// Detect * at start and end using a single regex
if (preg_match('/^\*(.*)\*$/', (string) $this->subparts[1], $matches)) {
$prefix = '.*';
}
if (preg_match('/\\*$/', (string) $this->subparts[1])) {
$suffix = '.*';
$search = $matches[1]; // Extract inner content
} else {
$search = trim((string) $this->subparts[1], '*');
if (str_starts_with((string) $this->subparts[1], '*')) {
$prefix = '.*';
}
if (str_ends_with((string) $this->subparts[1], '*')) {
$suffix = '.*';
}
}
$search = preg_replace(['/^\\*/','/\\*$/'], '', (string) $this->subparts[1]);
$escapedSearch = preg_quote($search, '/');
// Construct the pattern
if ($this->dnFilter) {
$this->pattern = '/'.$left.'='.$prefix.preg_quote((string) $search, '/').$suffix.',/';
} elseif ($this->subparts[1] == '*') {
$this->pattern = "/{$left}={$prefix}{$escapedSearch}{$suffix},/";
} elseif ($this->subparts[1] === '*') {
$this->pattern = '/^.*$/';
} else {
$this->pattern = '/^'.$prefix.preg_quote((string) $search, '/').$suffix.'$/';
$this->pattern = "/^{$prefix}{$escapedSearch}{$suffix}$/";
}
}
}
function isDnFilter ()
{
return $this->dnFilter;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment