Skip to content

Commit

Permalink
Merge pull request #18201 from kamil-tekiela/quoteString-in-UserGroups
Browse files Browse the repository at this point in the history
Use quoteString in UserGroups
  • Loading branch information
MauricioFauth committed Mar 3, 2023
2 parents 8123a81 + a6cfa89 commit a659874
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
12 changes: 5 additions & 7 deletions libraries/classes/ConfigStorage/UserGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public static function getHtmlForListingUsersofAGroup(
$usersTable = Util::backquote($configurableMenusFeature->database)
. '.' . Util::backquote($configurableMenusFeature->users);
$sql_query = 'SELECT `username` FROM ' . $usersTable
. " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup)
. "'";
. ' WHERE `usergroup`=' . $GLOBALS['dbi']->quoteString($userGroup, Connection::TYPE_CONTROL);
$result = $GLOBALS['dbi']->tryQueryAsControlUser($sql_query);
if ($result) {
$i = 0;
Expand Down Expand Up @@ -220,8 +219,7 @@ public static function getHtmlToEditUserGroup(
$groupTable = Util::backquote($configurableMenusFeature->database)
. '.' . Util::backquote($configurableMenusFeature->userGroups);
$sql_query = 'SELECT * FROM ' . $groupTable
. " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup)
. "'";
. ' WHERE `usergroup`=' . $GLOBALS['dbi']->quoteString($userGroup, Connection::TYPE_CONTROL);
$result = $GLOBALS['dbi']->tryQueryAsControlUser($sql_query);
if ($result) {
foreach ($result as $row) {
Expand Down Expand Up @@ -315,8 +313,7 @@ public static function edit(

if (! $new) {
$sql_query = 'DELETE FROM ' . $groupTable
. " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup)
. "';";
. ' WHERE `usergroup`=' . $GLOBALS['dbi']->quoteString($userGroup, Connection::TYPE_CONTROL) . ';';
$GLOBALS['dbi']->queryAsControlUser($sql_query);
}

Expand All @@ -333,7 +330,8 @@ public static function edit(

$tabName = $tabGroupName . '_' . $tab;
$allowed = isset($_POST[$tabName]) && $_POST[$tabName] === 'Y';
$sql_query .= "('" . $GLOBALS['dbi']->escapeString($userGroup) . "', '" . $tabName . "', '"
$sql_query .= '(' . $GLOBALS['dbi']->quoteString($userGroup, Connection::TYPE_CONTROL)
. ', ' . $GLOBALS['dbi']->quoteString($tabName, Connection::TYPE_CONTROL) . ", '"
. ($allowed ? 'Y' : 'N') . "')";
$first = false;
}
Expand Down
6 changes: 0 additions & 6 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -902,12 +902,6 @@
</RedundantCondition>
</file>
<file src="libraries/classes/ConfigStorage/UserGroups.php">
<DeprecatedMethod>
<code>escapeString</code>
<code>escapeString</code>
<code>escapeString</code>
<code>escapeString</code>
</DeprecatedMethod>
<MixedArgumentTypeCoercion>
<code>$tabNames</code>
</MixedArgumentTypeCoercion>
Expand Down
5 changes: 2 additions & 3 deletions test/classes/ConfigStorage/UserGroupsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@ public function testGetHtmlToEditUserGroup(): void
],
];
}));
$dbi->expects($this->any())
->method('escapeString')
->will($this->returnArgument(0));
$dbi->expects($this->any())->method('quoteString')
->will($this->returnCallback(static fn (string $string): string => "'" . $string . "'"));

$GLOBALS['dbi'] = $dbi;

Expand Down

0 comments on commit a659874

Please sign in to comment.