Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Introduce cleanRegexp()
Browse files Browse the repository at this point in the history
Use it instead of changing regexpToLike input parameter (less error prone)

Signed-off-by: Etienne CHAMPETIER <etienne.champetier@fiducial.net>
  • Loading branch information
Etienne CHAMPETIER committed Apr 23, 2014
1 parent 17b7c0b commit 5f5ff4d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 6 additions & 3 deletions core/src/core/classes/class.AJXP_Utils.php
Expand Up @@ -1852,21 +1852,24 @@ public static function glob_recursive($pattern, $flags = 0)
return $files;
}

public static function regexpToLike(&$regexp)
public static function regexpToLike($regexp)
{
$left = "~";
$right = "~";
if ($regexp[0]=="^") {
$regexp = ltrim($regexp, "^");
$left = "";
}
if ($regexp[strlen($regexp)-1] == "$") {
$regexp = rtrim($regexp, "$");
$right = "";
}
if ($left == "" && $right == "") {
return "= %s";
}
return "LIKE %".$left."like".$right;
}

public static function cleanRegexp($regexp)
{
return ltrim(rtrim($regexp, "$"), "^");
}
}
10 changes: 4 additions & 6 deletions core/src/plugins/auth.sql/class.sqlAuthDriver.php
Expand Up @@ -61,8 +61,7 @@ public function supportsUsersPagination()
public function listUsersPaginated($baseGroup, $regexp, $offset, $limit)
{
if ($regexp != null) {
$like = AJXP_Utils::regexpToLike($regexp);
$res = dibi::query("SELECT * FROM [ajxp_users] WHERE [login] ".$like." AND [groupPath] LIKE %like~ ORDER BY [login] ASC", $regexp, $baseGroup) ;
$res = dibi::query("SELECT * FROM [ajxp_users] WHERE [login] ".AJXP_Utils::regexpToLike($regexp)." AND [groupPath] LIKE %like~ ORDER BY [login] ASC", AJXP_Utils::cleanRegexp($regexp), $baseGroup) ;
} else if ($offset != -1 || $limit != -1) {
$res = dibi::query("SELECT * FROM [ajxp_users] WHERE [groupPath] LIKE %like~ ORDER BY [login] ASC %lmt %ofs", $baseGroup, $limit, $offset);
} else {
Expand All @@ -84,7 +83,7 @@ public function getUsersCount($baseGroup = "/", $regexp = "", $filterProperty =

$wheres = array();
if(!empty($regexp)){
$wheres[] = "[ajxp_users].[login] ". AJXP_Utils::regexpToLike($regexp);
$wheres[] = "[ajxp_users].[login] ".AJXP_Utils::regexpToLike($regexp);
}
$wheres[] = "[ajxp_users].[groupPath] LIKE %like~";

Expand Down Expand Up @@ -119,9 +118,8 @@ public function getUsersCount($baseGroup = "/", $regexp = "", $filterProperty =


if (!empty($regexp)) {
$res = dibi::query($q, $regexp, $baseGroup);
//$like = AJXP_Utils::regexpToLike($regexp);
//$res = dibi::query("SELECT COUNT(*) FROM [ajxp_users] WHERE [login] ".$like." AND [groupPath] LIKE %like~", $regexp, $baseGroup) ;
$res = dibi::query($q, AJXP_Utils::cleanRegexp($regexp), $baseGroup);
//$res = dibi::query("SELECT COUNT(*) FROM [ajxp_users] WHERE [login] ".AJXP_Utils::regexpToLike($regexp)." AND [groupPath] LIKE %like~", AJXP_Utils::cleanRegexp($regexp), $baseGroup) ;
} else {
$res = dibi::query($q, $baseGroup);
//$res = dibi::query("SELECT COUNT(*) FROM [ajxp_users] WHERE [groupPath] LIKE %like~", $baseGroup);
Expand Down

0 comments on commit 5f5ff4d

Please sign in to comment.