Skip to content

Commit 7bbf4fb

Browse files
rlerdorfkrakjoe
authored andcommitted
Expose internal key check via checkKey() method Make ascii key check consistent with libmemcached's isgraph() check Add test to check that they match
1 parent c2a3194 commit 7bbf4fb

4 files changed

+34
-3
lines changed

php_memcached.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ zend_bool s_memc_valid_key_ascii(zend_string *key)
228228
size_t i, len = ZSTR_LEN(key);
229229

230230
for (i = 0; i < len; i++) {
231-
if (iscntrl(str[i]) || isspace(str[i]))
231+
if (!isgraph(str[i]) || isspace(str[i]))
232232
return 0;
233233
}
234234
return 1;
@@ -3450,6 +3450,24 @@ static PHP_METHOD(Memcached, isPristine)
34503450
}
34513451
/* }}} */
34523452

3453+
/* {{{ bool Memcached::checkKey(string key)
3454+
Checks if a key is valid */
3455+
PHP_METHOD(Memcached, checkKey)
3456+
{
3457+
zend_string *key;
3458+
MEMC_METHOD_INIT_VARS;
3459+
3460+
ZEND_PARSE_PARAMETERS_START(1, 1)
3461+
Z_PARAM_STR(key)
3462+
ZEND_PARSE_PARAMETERS_END();
3463+
3464+
MEMC_METHOD_FETCH_OBJECT;
3465+
s_memc_set_status(intern, MEMCACHED_SUCCESS, 0);
3466+
MEMC_CHECK_KEY(intern, key);
3467+
RETURN_TRUE;
3468+
}
3469+
/* }}} */
3470+
34533471
/****************************************
34543472
Internal support code
34553473
****************************************/

php_memcached.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function setEncodingKey(string $key): bool {}
8383
#endif
8484
public function isPersistent(): bool {}
8585
public function isPristine(): bool {}
86+
public function checkKey(string $key): bool {}
8687
}
8788

8889
#ifdef HAVE_MEMCACHED_PROTOCOL

php_memcached_arginfo.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 573d35c5c6b6c397943e0f8ab9c505e2f4ce9e34 */
2+
* Stub hash: 3f4694d4e1f3d1647a832acd8539b056b2ab5e7a */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Memcached___construct, 0, 0, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, persistent_id, IS_STRING, 1, "null")
@@ -249,6 +249,10 @@ ZEND_END_ARG_INFO()
249249

250250
#define arginfo_class_Memcached_isPristine arginfo_class_Memcached_resetServerList
251251

252+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Memcached_checkKey, 0, 1, _IS_BOOL, 0)
253+
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
254+
ZEND_END_ARG_INFO()
255+
252256
#if defined(HAVE_MEMCACHED_PROTOCOL)
253257
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_MemcachedServer_run, 0, 1, _IS_BOOL, 0)
254258
ZEND_ARG_TYPE_INFO(0, address, IS_STRING, 0)
@@ -325,6 +329,7 @@ ZEND_METHOD(Memcached, setEncodingKey);
325329
#endif
326330
ZEND_METHOD(Memcached, isPersistent);
327331
ZEND_METHOD(Memcached, isPristine);
332+
ZEND_METHOD(Memcached, checkKey);
328333
#if defined(HAVE_MEMCACHED_PROTOCOL)
329334
ZEND_METHOD(MemcachedServer, run);
330335
#endif
@@ -396,6 +401,7 @@ static const zend_function_entry class_Memcached_methods[] = {
396401
#endif
397402
ZEND_ME(Memcached, isPersistent, arginfo_class_Memcached_isPersistent, ZEND_ACC_PUBLIC)
398403
ZEND_ME(Memcached, isPristine, arginfo_class_Memcached_isPristine, ZEND_ACC_PUBLIC)
404+
ZEND_ME(Memcached, checkKey, arginfo_class_Memcached_checkKey, ZEND_ACC_PUBLIC)
399405
ZEND_FE_END
400406
};
401407

php_memcached_legacy_arginfo.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 573d35c5c6b6c397943e0f8ab9c505e2f4ce9e34 */
2+
* Stub hash: 3f4694d4e1f3d1647a832acd8539b056b2ab5e7a */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Memcached___construct, 0, 0, 0)
55
ZEND_ARG_INFO(0, persistent_id)
@@ -245,6 +245,10 @@ ZEND_END_ARG_INFO()
245245

246246
#define arginfo_class_Memcached_isPristine arginfo_class_Memcached_getResultCode
247247

248+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Memcached_checkKey, 0, 0, 1)
249+
ZEND_ARG_INFO(0, key)
250+
ZEND_END_ARG_INFO()
251+
248252
#if defined(HAVE_MEMCACHED_PROTOCOL)
249253
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MemcachedServer_run, 0, 0, 1)
250254
ZEND_ARG_INFO(0, address)
@@ -321,6 +325,7 @@ ZEND_METHOD(Memcached, setEncodingKey);
321325
#endif
322326
ZEND_METHOD(Memcached, isPersistent);
323327
ZEND_METHOD(Memcached, isPristine);
328+
ZEND_METHOD(Memcached, checkKey);
324329
#if defined(HAVE_MEMCACHED_PROTOCOL)
325330
ZEND_METHOD(MemcachedServer, run);
326331
#endif
@@ -392,6 +397,7 @@ static const zend_function_entry class_Memcached_methods[] = {
392397
#endif
393398
ZEND_ME(Memcached, isPersistent, arginfo_class_Memcached_isPersistent, ZEND_ACC_PUBLIC)
394399
ZEND_ME(Memcached, isPristine, arginfo_class_Memcached_isPristine, ZEND_ACC_PUBLIC)
400+
ZEND_ME(Memcached, checkKey, arginfo_class_Memcached_checkKey, ZEND_ACC_PUBLIC)
395401
ZEND_FE_END
396402
};
397403

0 commit comments

Comments
 (0)