Skip to content
This repository was archived by the owner on Feb 5, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/CouchDB/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private function createDocumentAttachments($documentId, $data)
$basePath = '/' . $this->dm->getCouchDBClient()->getDatabase() . '/' . $documentId . '/';
foreach ($data AS $filename => $attachment) {
if (isset($attachment['stub']) && $attachment['stub']) {
$instance = Attachment::createStub($attachment['content_type'], $attachment['length'], $attachment['revpos'], $client, $basePath . $filename);
$instance = Attachment::createStub($attachment['content_type'], $attachment['length'], $attachment['revpos'], $client, $basePath . urlencode($filename));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure this is something that the Attachment class should fix, not the calling code. Or?

} else if (isset($attachment['data'])) {
$instance = Attachment::createFromBase64Data($attachment['data'], $attachment['content_type'], $attachment['revpos']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ public function setUp()
$this->dm = $this->createDocumentManager();
$client = $this->dm->getHttpClient();
$response = $client->request('PUT', '/' . $this->getTestDatabase() . '/user_with_attachment', \file_get_contents(__DIR__ . "/_files/user_with_attachment.json"));
$response = $client->request('PUT', '/' . $this->getTestDatabase() . '/attachment_with_spaces_in_name', \file_get_contents(__DIR__ . "/_files/attachment_with_spaces_in_name.json"));
}

public function testGetAttachmentWithSpacesInName()
{
$user = $this->dm->find('Doctrine\Tests\Models\CMS\CmsUser', 'attachment_with_spaces_in_name');
$this->assertArrayHasKey('attachment with spaces.txt', $user->attachments);
$this->assertInstanceOf('Doctrine\CouchDB\Attachment', $user->attachments['attachment with spaces.txt']);
$this->assertEquals('This is a base64 encoded text', $user->attachments['attachment with spaces.txt']->getRawData());
}

public function testHydrateAttachments()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"_id": "attachment_with_spaces_in_name",
"_attachments":
{
"attachment with spaces.txt":
{
"content_type":"text\/plain",
"data": "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
}
},
"type": "Doctrine.Tests.Models.CMS.CmsUser"
}