Skip to content

Commit c8b6848

Browse files
committed
Merge pull request #734 from TroodoNmike/master
making sure id is urlencoded when using updateDocument
2 parents 990b89f + ecefc85 commit c8b6848

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/Elastica/Type.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ public function updateDocument($data, array $options = array())
148148
throw new InvalidException('Document or Script id is not set');
149149
}
150150

151+
$id = urlencode($data->getId());
152+
151153
return $this->getIndex()->getClient()->updateDocument(
152-
$data->getId(),
154+
$id,
153155
$data,
154156
$this->getIndex()->getName(),
155157
$this->getName(),

test/lib/Elastica/Test/TypeTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,32 @@ public function testUpdateDocument()
565565
$this->assertEquals(3, $updatedDoc['counter'], "Counter was not incremented");
566566
}
567567

568+
public function testUpdateDocumentWithIdForwardSlashes()
569+
{
570+
$client = $this->_getClient();
571+
$index = $client->getIndex('elastica_test');
572+
$type = $index->getType('update_type');
573+
$id = '/id/with/forward/slashes';
574+
$type->addDocument(new Document($id, array('name' => 'bruce wayne batman', 'counter' => 1)));
575+
$newName = 'batman';
576+
577+
$document = new Document();
578+
$script = new Script(
579+
"ctx._source.name = name; ctx._source.counter += count",
580+
array(
581+
'name' => $newName,
582+
'count' => 2,
583+
),
584+
null,
585+
$id
586+
);
587+
$script->setUpsert($document);
588+
589+
$type->updateDocument($script, array('refresh' => true));
590+
$updatedDoc = $type->getDocument($id)->getData();
591+
$this->assertEquals($newName, $updatedDoc['name'], "Name was not updated");
592+
$this->assertEquals(3, $updatedDoc['counter'], "Counter was not incremented");
593+
}
568594
public function testUpdateDocumentWithParameter()
569595
{
570596
$client = $this->_getClient();

0 commit comments

Comments
 (0)