Skip to content

Commit

Permalink
Merge pull request #734 from TroodoNmike/master
Browse files Browse the repository at this point in the history
making sure id is urlencoded when using updateDocument
  • Loading branch information
ruflin committed Dec 18, 2014
2 parents 990b89f + ecefc85 commit c8b6848
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Elastica/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ public function updateDocument($data, array $options = array())
throw new InvalidException('Document or Script id is not set');
}

$id = urlencode($data->getId());

return $this->getIndex()->getClient()->updateDocument(
$data->getId(),
$id,
$data,
$this->getIndex()->getName(),
$this->getName(),
Expand Down
26 changes: 26 additions & 0 deletions test/lib/Elastica/Test/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,32 @@ public function testUpdateDocument()
$this->assertEquals(3, $updatedDoc['counter'], "Counter was not incremented");
}

public function testUpdateDocumentWithIdForwardSlashes()
{
$client = $this->_getClient();
$index = $client->getIndex('elastica_test');
$type = $index->getType('update_type');
$id = '/id/with/forward/slashes';
$type->addDocument(new Document($id, array('name' => 'bruce wayne batman', 'counter' => 1)));
$newName = 'batman';

$document = new Document();
$script = new Script(
"ctx._source.name = name; ctx._source.counter += count",
array(
'name' => $newName,
'count' => 2,
),
null,
$id
);
$script->setUpsert($document);

$type->updateDocument($script, array('refresh' => true));
$updatedDoc = $type->getDocument($id)->getData();
$this->assertEquals($newName, $updatedDoc['name'], "Name was not updated");
$this->assertEquals(3, $updatedDoc['counter'], "Counter was not incremented");
}
public function testUpdateDocumentWithParameter()
{
$client = $this->_getClient();
Expand Down

0 comments on commit c8b6848

Please sign in to comment.