diff --git a/lib/DAV/Server.php b/lib/DAV/Server.php index e122b2447a..e87d4db400 100644 --- a/lib/DAV/Server.php +++ b/lib/DAV/Server.php @@ -1581,7 +1581,7 @@ public function getIfConditions(RequestInterface $request) $matches = []; - $regex = '/(?:\<(?P.*?)\>\s)?\((?PNot\s)?(?:\<(?P[^\>]*)\>)?(?:\s?)(?:\[(?P[^\]]*)\])?\)/im'; + $regex = '/(?:\<(?P.*?)\>\s)?\((?Pnot\b[\x20\t]*)?(?:\<(?P[^\>]*)\>)?(?:\s?)(?:\[(?P[^\]]*)\])?\)/im'; preg_match_all($regex, $header, $matches, PREG_SET_ORDER); $conditions = []; diff --git a/tests/Sabre/DAV/GetIfConditionsTest.php b/tests/Sabre/DAV/GetIfConditionsTest.php index afee554377..4c2fa00fad 100644 --- a/tests/Sabre/DAV/GetIfConditionsTest.php +++ b/tests/Sabre/DAV/GetIfConditionsTest.php @@ -60,6 +60,75 @@ public function testNotLockToken() self::assertEquals($compare, $conditions); } + public function testNotLockTokenWithoutSpace() + { + $request = new HTTP\Request('GET', '/bla', [ + 'If' => '(Not)', + ]); + + $conditions = $this->server->getIfConditions($request); + + $compare = [ + [ + 'uri' => 'bla', + 'tokens' => [ + [ + 'negate' => true, + 'token' => 'opaquelocktoken:token1', + 'etag' => '', + ], + ], + ], + ]; + self::assertEquals($compare, $conditions); + } + + public function testUppercaseNotLockTokenWithTab() + { + $request = new HTTP\Request('GET', '/bla', [ + 'If' => "(NOT\t)", + ]); + + $conditions = $this->server->getIfConditions($request); + + $compare = [ + [ + 'uri' => 'bla', + 'tokens' => [ + [ + 'negate' => true, + 'token' => 'opaquelocktoken:token1', + 'etag' => '', + ], + ], + ], + ]; + self::assertEquals($compare, $conditions); + } + + public function testUppercaseNotLockTokenWithoutSpace() + { + $request = new HTTP\Request('GET', '/bla', [ + 'If' => '(NOT)', + ]); + + $conditions = $this->server->getIfConditions($request); + + $compare = [ + [ + 'uri' => 'bla', + 'tokens' => [ + [ + 'negate' => true, + 'token' => 'opaquelocktoken:token1', + 'etag' => '', + ], + ], + ], + ]; + self::assertEquals($compare, $conditions); + } + public function testLockTokenUrl() { $request = new HTTP\Request('GET', '/bla', [ @@ -204,6 +273,75 @@ public function testEtag() self::assertEquals($compare, $conditions); } + public function testNotEtagWithoutSpace() + { + $request = new HTTP\Request('GET', '/foo', [ + 'If' => '(Not["etag1"])', + ]); + + $conditions = $this->server->getIfConditions($request); + + $compare = [ + [ + 'uri' => 'foo', + 'tokens' => [ + [ + 'negate' => true, + 'token' => '', + 'etag' => '"etag1"', + ], + ], + ], + ]; + self::assertEquals($compare, $conditions); + } + + public function testUppercaseNotEtagWithTab() + { + $request = new HTTP\Request('GET', '/foo', [ + 'If' => "(NOT\t[\"etag1\"])", + ]); + + $conditions = $this->server->getIfConditions($request); + + $compare = [ + [ + 'uri' => 'foo', + 'tokens' => [ + [ + 'negate' => true, + 'token' => '', + 'etag' => '"etag1"', + ], + ], + ], + ]; + self::assertEquals($compare, $conditions); + } + + public function testUppercaseNotEtagWithoutSpace() + { + $request = new HTTP\Request('GET', '/foo', [ + 'If' => '(NOT["etag1"])', + ]); + + $conditions = $this->server->getIfConditions($request); + + $compare = [ + [ + 'uri' => 'foo', + 'tokens' => [ + [ + 'negate' => true, + 'token' => '', + 'etag' => '"etag1"', + ], + ], + ], + ]; + self::assertEquals($compare, $conditions); + } + public function test2Etags() { $request = new HTTP\Request('GET', '/foo', [