diff --git a/lib/Doctrine/CouchDB/Attachment.php b/lib/Doctrine/CouchDB/Attachment.php index 7fd5a9f..a9ed16a 100644 --- a/lib/Doctrine/CouchDB/Attachment.php +++ b/lib/Doctrine/CouchDB/Attachment.php @@ -146,7 +146,13 @@ public function getBase64EncodedData() private function lazyLoad() { if ($this->stub) { - $response = $this->httpClient->request('GET', $this->path, null, true); // raw request + $pathInfo = pathinfo($this->path); + $response = $this->httpClient->request( + 'GET', + sprintf('%s/%s', $pathInfo['dirname'], urlencode($pathInfo['basename'])), + null, + true + ); // raw request if ($response->status != 200) { throw HTTPException::fromResponse($this->path, $response); } diff --git a/tests/Doctrine/Tests/CouchDB/Functional/CouchDBClientTest.php b/tests/Doctrine/Tests/CouchDB/Functional/CouchDBClientTest.php index a235727..685eb34 100644 --- a/tests/Doctrine/Tests/CouchDB/Functional/CouchDBClientTest.php +++ b/tests/Doctrine/Tests/CouchDB/Functional/CouchDBClientTest.php @@ -1,6 +1,7 @@ assertEquals(0, $result->getTotalRows()); } + + public function testAttachmentWithSpaces() + { + $filename = 'foo bar.txt'; + $data = 'foobar fooobar fooobar'; + $this->couchClient->putDocument(array( + '_attachments' => + array( + $filename => + array( + 'content_type' => 'text/plain', + 'data' => base64_encode($data), + ), + ), + ), 'foobar-1'); + $doc = $this->couchClient->findDocument('foobar-1')->body; + + $attachment = Attachment::createStub( + $doc['_attachments'][$filename]['content_type'], + $doc['_attachments'][$filename]['length'], + $doc['_attachments'][$filename]['revpos'], + $this->couchClient->getHttpClient(), + sprintf( + '/%s/%s/%s', + $this->getTestDatabase(), + $doc['_id'], + $filename + ) + ); + $this->assertEquals($data, $attachment->getRawData()); + } }