jenkins-bot has submitted this change and it was merged.
Change subject: Fix escaping for MSSQL LIKE queries.
......................................................................
Fix escaping for MSSQL LIKE queries.
MSSQL allows for more operators than standard LIKE queries. In addition,
an ESCAPE clause must be specified in order to backslash-escapes to work.
Bug: T73207
Change-Id: Idadf9d56cadc48cf47d000598d8a3214c684f9d5
---
M includes/db/DatabaseMssql.php
1 file changed, 29 insertions(+), 0 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
Parent5446: Looks good to me, but someone else must approve
Skizzerz: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php
index af3cc72..1f39e1f 100644
--- a/includes/db/DatabaseMssql.php
+++ b/includes/db/DatabaseMssql.php
@@ -1165,6 +1165,35 @@
}
/**
+ * MS SQL supports more pattern operators than other databases (ex:
[,],^)
+ *
+ * @param string $s
+ * @return string
+ */
+ protected function escapeLikeInternal( $s ) {
+ return addcslashes( $s, '\%_[]^' );
+ }
+
+ /**
+ * MS SQL requires specifying the escape character used in a LIKE query
+ * or using Square brackets to surround characters that are to be
escaped
+ * http://msdn.microsoft.com/en-us/library/ms179859.aspx
+ * Here we take the Specify-Escape-Character approach since it's less
+ * invasive, renders a query that is closer to other DB's and better at
+ * handling square bracket escaping
+ *
+ * @return string Fully built LIKE statement
+ */
+ public function buildLike() {
+ $params = func_get_args();
+ if ( count( $params ) > 0 && is_array( $params[0] ) ) {
+ $params = $params[0];
+ }
+
+ return parent::buildLike( $params ) . " ESCAPE '\' ";
+ }
+
+ /**
* @param string $db
* @return bool
*/
--
To view, visit https://gerrit.wikimedia.org/r/162508
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Idadf9d56cadc48cf47d000598d8a3214c684f9d5
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Emadelwany <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Emadelwany <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: MarkAHershberger <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: PleaseStand <[email protected]>
Gerrit-Reviewer: Skizzerz <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits