Merge branch '17.0' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2023-04-15 02:29:01 +02:00
commit f02ff3f774
4 changed files with 41 additions and 3 deletions

View File

@ -484,7 +484,7 @@ class DoliDBMysqli extends DoliDB
*/
public function escapeforlike($stringtoencode)
{
return str_replace(array('_', '\\', '%'), array('\_', '\\\\', '\%'), (string) $stringtoencode);
return str_replace(array('\\', '_', '%'), array('\\\\', '\_', '\%'), (string) $stringtoencode);
}
/**

View File

@ -729,7 +729,7 @@ class DoliDBPgsql extends DoliDB
*/
public function escapeforlike($stringtoencode)
{
return str_replace(array('_', '\\', '%'), array('\_', '\\\\', '\%'), (string) $stringtoencode);
return str_replace(array('\\', '_', '%'), array('\\\\', '\_', '\%'), (string) $stringtoencode);
}
/**

View File

@ -657,7 +657,7 @@ class DoliDBSqlite3 extends DoliDB
*/
public function escapeforlike($stringtoencode)
{
return str_replace(array('_', '\\', '%'), array('\_', '\\\\', '\%'), (string) $stringtoencode);
return str_replace(array('\\', '_', '%'), array('\\\\', '\_', '\%'), (string) $stringtoencode);
}
/**

View File

@ -157,6 +157,44 @@ class CodingSqlTest extends PHPUnit\Framework\TestCase
print __METHOD__."\n";
}
/**
* testEscape
*
* @return string
*/
public function testEscape()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$a = 'abc"\'def';
print $a;
$result = $db->escape($a); // $result must be abc\"\'def
$this->assertEquals('abc\"\\\'def', $result);
}
/**
* testEscapeForLike
*
* @return string
*/
public function testEscapeForLike()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$a = 'abc"\'def_ghi%klm\\nop';
//print $a;
$result = $db->escapeforlike($a); // $result must be abc"'def\_ghi\%klm\\nop
$this->assertEquals('abc"\'def\_ghi\%klm\\\\nop', $result);
}
/**
* testSql
*