From d04da19a45d7158d3c863d55b0254ea8d474e48f Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Sun, 17 Feb 2019 11:02:34 +0000 Subject: [PATCH] Make addIdentifierQuotes part of IDatabase This is so it can be used in places that typehint an IDatabase, ultimately so that I can make phan-taint-check happy. Bug: T216348 Change-Id: Iabf3e9a6add380322a12cdbb6a337bad690f1370 --- includes/libs/rdbms/database/DBConnRef.php | 4 ++++ includes/libs/rdbms/database/Database.php | 9 --------- includes/libs/rdbms/database/IDatabase.php | 11 +++++++++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/includes/libs/rdbms/database/DBConnRef.php b/includes/libs/rdbms/database/DBConnRef.php index f693dd500b..ab70fc80cc 100644 --- a/includes/libs/rdbms/database/DBConnRef.php +++ b/includes/libs/rdbms/database/DBConnRef.php @@ -392,6 +392,10 @@ class DBConnRef implements IDatabase { return $this->__call( __FUNCTION__, func_get_args() ); } + public function addIdentifierQuotes( $s ) { + return $this->__call( __FUNCTION__, func_get_args() ); + } + public function buildLike() { return $this->__call( __FUNCTION__, func_get_args() ); } diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index 974c7df46e..174182f2f1 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -2664,15 +2664,6 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } } - /** - * Quotes an identifier using `backticks` or "double quotes" depending on the database type. - * MySQL uses `backticks` while basically everything else uses double quotes. - * Since MySQL is the odd one out here the double quotes are our generic - * and we implement backticks in DatabaseMysqlBase. - * - * @param string $s - * @return string - */ public function addIdentifierQuotes( $s ) { return '"' . str_replace( '"', '""', $s ) . '"'; } diff --git a/includes/libs/rdbms/database/IDatabase.php b/includes/libs/rdbms/database/IDatabase.php index 27958838fb..7d9eac1a57 100644 --- a/includes/libs/rdbms/database/IDatabase.php +++ b/includes/libs/rdbms/database/IDatabase.php @@ -1155,6 +1155,17 @@ interface IDatabase { */ public function addQuotes( $s ); + /** + * Quotes an identifier, in order to make user controlled input safe + * + * Depending on the database this will either be `backticks` or "double quotes" + * + * @param string $s + * @return string + * @since 1.33 + */ + public function addIdentifierQuotes( $s ); + /** * LIKE statement wrapper, receives a variable-length argument list with * parts of pattern to match containing either string literals that will be -- 2.20.1