From d4cbb00d3baa8fa49453fa48f32c70ba98b2c57a Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 9 Aug 2012 11:40:55 -0700 Subject: [PATCH] Fix offset-without-limit case in Policy query Summary: Apparently I am not qualified to do basic math. Test Plan: Unit test. Reviewers: vrana Reviewed By: vrana CC: aran Differential Revision: https://secure.phabricator.com/D3218 --- .../policy/__tests__/PhabricatorPolicyTestCase.php | 6 +++++- src/infrastructure/query/policy/PhabricatorPolicyQuery.php | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/applications/policy/__tests__/PhabricatorPolicyTestCase.php b/src/applications/policy/__tests__/PhabricatorPolicyTestCase.php index 08a793b8b7..2f305ff866 100644 --- a/src/applications/policy/__tests__/PhabricatorPolicyTestCase.php +++ b/src/applications/policy/__tests__/PhabricatorPolicyTestCase.php @@ -133,6 +133,11 @@ final class PhabricatorPolicyTestCase extends PhabricatorTestCase { 2, count($query->setLimit(3)->setOffset(1)->execute()), 'Offsets work correctly.'); + + $this->assertEqual( + 2, + count($query->setLimit(0)->setOffset(1)->execute()), + 'Offset with no limit works.'); } @@ -165,7 +170,6 @@ final class PhabricatorPolicyTestCase extends PhabricatorTestCase { } - /** * Test an object for visibility across multiple user specifications. */ diff --git a/src/infrastructure/query/policy/PhabricatorPolicyQuery.php b/src/infrastructure/query/policy/PhabricatorPolicyQuery.php index d9c29e1350..a1dc23ae26 100644 --- a/src/infrastructure/query/policy/PhabricatorPolicyQuery.php +++ b/src/infrastructure/query/policy/PhabricatorPolicyQuery.php @@ -153,7 +153,11 @@ abstract class PhabricatorPolicyQuery extends PhabricatorOffsetPagedQuery { $limit = (int)$this->getLimit(); $count = 0; - $need = $offset + $limit; + if ($limit) { + $need = $offset + $limit; + } else { + $need = 0; + } $this->willExecute();