From 798cc41a51f5df1f06c144923f70f269209be07c Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Tue, 7 Oct 2008 18:23:39 +0000 Subject: [PATCH] (bug 15881) API: Empty or invalid parameters cause database errors --- RELEASE-NOTES | 1 + includes/api/ApiQueryBase.php | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 73c3c3b11b..11f7fe02af 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -311,6 +311,7 @@ The following extensions are migrated into MediaWiki 1.14: * (bug 15767) apfilterlanglinks returns duplicate results * (bug 15845) Added pageid/fromid parameter to action=delete/move, making manipulation of legacy pages with invalid titles possible +* (bug 15881) Empty or invalid parameters cause database errors === Languages updated in 1.14 === diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index 61fb3658ec..26792a7a51 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -126,13 +126,19 @@ abstract class ApiQueryBase extends ApiBase { * Clauses can be formatted as 'foo=bar' or array('foo' => 'bar'), * the latter only works if the value is a constant (i.e. not another field) * + * If $value is an empty array, this function does nothing. + * * For example, array('foo=bar', 'baz' => 3, 'bla' => 'foo') translates * to "foo=bar AND baz='3' AND bla='foo'" * @param mixed $value String or array */ protected function addWhere($value) { - if (is_array($value)) - $this->where = array_merge($this->where, $value); + if (is_array($value)) { + // Sanity check: don't insert empty arrays, + // Database::makeList() chokes on them + if(!empty($value)) + $this->where = array_merge($this->where, $value); + } else $this->where[] = $value; } @@ -157,7 +163,7 @@ abstract class ApiQueryBase extends ApiBase { * @param string $value Value; ignored if nul; */ protected function addWhereFld($field, $value) { - if (!is_null($value)) + if (!is_null($value) && !empty($value)) $this->where[$field] = $value; } -- 2.20.1