Skip to content
This repository was archived by the owner on Apr 20, 2022. It is now read-only.

Commit d09b663

Browse files
committed
Revert "Revert "PCBC-227: Allow store of pure numeric keys""
This reverts commit afe5200. Change-Id: Id5aab9c0b4a7009fd9b89fabe772bd903b863259 Reviewed-on: http://review.couchbase.org/29201 Reviewed-by: Trond Norbye <trond.norbye@gmail.com> Tested-by: Trond Norbye <trond.norbye@gmail.com>
1 parent 48b6d36 commit d09b663

File tree

3 files changed

+96
-8
lines changed

3 files changed

+96
-8
lines changed

store.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,20 @@ void php_couchbase_store_multi_impl_oo(INTERNAL_FUNCTION_PARAMETERS)
687687
char *payload;
688688
unsigned int flags = 0;
689689
zval **ppzval;
690-
691-
if (zend_hash_get_current_key_type(Z_ARRVAL_P(akeys)) != HASH_KEY_IS_STRING) {
690+
int allocated_key = 0;
691+
692+
switch (zend_hash_get_current_key_type(Z_ARRVAL_P(akeys))) {
693+
case HASH_KEY_IS_LONG: {
694+
ulong kval;
695+
zend_hash_get_current_key(Z_ARRVAL_P(akeys), &key, &kval, 0);
696+
spprintf(&key, 0, "%llu", kval);
697+
allocated_key = 1;
698+
}
699+
break;
700+
case HASH_KEY_IS_STRING:
701+
zend_hash_get_current_key(Z_ARRVAL_P(akeys), &key, NULL, 0);
702+
break;
703+
default: {
692704
int xx;
693705
for (xx = 0; xx < ii; ++xx) {
694706
efree((void *)cmds[xx].v.v0.bytes);
@@ -703,9 +715,10 @@ void php_couchbase_store_multi_impl_oo(INTERNAL_FUNCTION_PARAMETERS)
703715
0 TSRMLS_CC);
704716
return ;
705717
}
718+
}
706719

707-
zend_hash_get_current_key(Z_ARRVAL_P(akeys), &key, NULL, 0);
708-
if ((klen = strlen(key)) == 0) {
720+
klen = strlen(key);
721+
if (klen == 0) {
709722
int xx;
710723
for (xx = 0; xx < ii; ++xx) {
711724
efree((void *)cmds[xx].v.v0.bytes);
@@ -750,7 +763,9 @@ void php_couchbase_store_multi_impl_oo(INTERNAL_FUNCTION_PARAMETERS)
750763

751764
if (couchbase_res->prefix_key_len) {
752765
char *new_key;
753-
klen = spprintf(&new_key, 0, "%s_%s", couchbase_res->prefix_key, key);
766+
allocated_key = 1;
767+
klen = spprintf(&new_key, 0, "%s_%s", couchbase_res->prefix_key,
768+
key);
754769
key = new_key;
755770
}
756771

@@ -765,7 +780,7 @@ void php_couchbase_store_multi_impl_oo(INTERNAL_FUNCTION_PARAMETERS)
765780
cmds[ii].v.v0.flags = flags;
766781
cmds[ii].v.v0.exptime = exp;
767782

768-
if (couchbase_res->prefix_key_len) {
783+
if (allocated_key) {
769784
efree(key);
770785
}
771786
}

tests/Regression.inc

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ class Regression extends CouchbaseTestCommon {
1818
} catch (Exception $exp) {
1919
$msg = $exp->getMessage();
2020
}
21-
$this->assertEquals("Invalid key specified (not a string)",
22-
$msg);
2321
}
2422

2523
function testPCBC_218() {
@@ -48,4 +46,65 @@ class Regression extends CouchbaseTestCommon {
4846
$this->assertEquals("", $msg);
4947
}
5048

49+
function testPCBC_227() {
50+
$oo = $this->oo;
51+
$msg = "";
52+
53+
54+
try {
55+
couchbase_set($this->handle, "1234", "foo");
56+
} catch (Exception $exp) {
57+
$msg = $exp->getMessage();
58+
}
59+
$this->assertEquals("", $msg);
60+
61+
try {
62+
couchbase_set($this->handle, 1234, "foo");
63+
} catch (Exception $exp) {
64+
$msg = $exp->getMessage();
65+
}
66+
$this->assertEquals("", $msg);
67+
68+
try {
69+
couchbase_set_multi($this->handle, array("1234" => "foo"));
70+
} catch (Exception $exp) {
71+
$msg = $exp->getMessage();
72+
}
73+
$this->assertEquals("", $msg);
74+
75+
try {
76+
couchbase_set_multi($this->handle, array(1234 => "foo"));
77+
} catch (Exception $exp) {
78+
$msg = $exp->getMessage();
79+
}
80+
$this->assertEquals("", $msg);
81+
82+
try {
83+
$oo->set("1234", "foo");
84+
} catch (Exception $exp) {
85+
$msg = $exp->getMessage();
86+
}
87+
$this->assertEquals("", $msg);
88+
89+
try {
90+
$oo->set(1234, "foo");
91+
} catch (Exception $exp) {
92+
$msg = $exp->getMessage();
93+
}
94+
$this->assertEquals("", $msg);
95+
96+
try {
97+
$oo->setMulti(array("1234" => "foo"));
98+
} catch (Exception $exp) {
99+
$msg = $exp->getMessage();
100+
}
101+
$this->assertEquals("", $msg);
102+
103+
try {
104+
$oo->setMulti(array(1234 => "foo"));
105+
} catch (Exception $exp) {
106+
$msg = $exp->getMessage();
107+
}
108+
$this->assertEquals("", $msg);
109+
}
51110
}

tests/phpt/Regression/PCBC_227.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Regression - PCBC_227
3+
4+
--SKIPIF--
5+
<?php
6+
include dirname(__FILE__)."/../../cbtestframework/cbtest-phpt-loader.inc";
7+
couchbase_phpt_skipif("Regression", "testPCBC_227");
8+
9+
--FILE--
10+
<?php
11+
include dirname(__FILE__)."/../../cbtestframework/cbtest-phpt-loader.inc";
12+
couchbase_phpt_runtest("Regression", "testPCBC_227");
13+
--EXPECT--
14+
PHP_COUCHBASE_OK

0 commit comments

Comments
 (0)