Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Expose internal key check via checkKey() method
Make ascii key check consistent with libmemcached's isgraph() check
Add test to check that they match
  • Loading branch information
rlerdorf committed Feb 25, 2021
commit 2481eb2c4dc5919a7abc3ecf4278cad3aae780b5
20 changes: 19 additions & 1 deletion php_memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ zend_bool s_memc_valid_key_ascii(zend_string *key)
size_t i, len = ZSTR_LEN(key);

for (i = 0; i < len; i++) {
if (iscntrl(str[i]) || isspace(str[i]))
if (!isgraph(str[i]) || isspace(str[i]))
return 0;
}
return 1;
Expand Down Expand Up @@ -3450,6 +3450,24 @@ static PHP_METHOD(Memcached, isPristine)
}
/* }}} */

/* {{{ bool Memcached::checkKey(string key)
Checks if a key is valid */
PHP_METHOD(Memcached, checkKey)
{
zend_string *key;
MEMC_METHOD_INIT_VARS;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR(key)
ZEND_PARSE_PARAMETERS_END();

MEMC_METHOD_FETCH_OBJECT;
s_memc_set_status(intern, MEMCACHED_SUCCESS, 0);
MEMC_CHECK_KEY(intern, key);
RETURN_TRUE;
}
/* }}} */

/****************************************
Internal support code
****************************************/
Expand Down
1 change: 1 addition & 0 deletions php_memcached.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function setEncodingKey(string $key): bool {}
#endif
public function isPersistent(): bool {}
public function isPristine(): bool {}
public function checkKey(string $key): bool {}
}

#ifdef HAVE_MEMCACHED_PROTOCOL
Expand Down
8 changes: 7 additions & 1 deletion php_memcached_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 573d35c5c6b6c397943e0f8ab9c505e2f4ce9e34 */
* Stub hash: 3f4694d4e1f3d1647a832acd8539b056b2ab5e7a */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Memcached___construct, 0, 0, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, persistent_id, IS_STRING, 1, "null")
Expand Down Expand Up @@ -249,6 +249,10 @@ ZEND_END_ARG_INFO()

#define arginfo_class_Memcached_isPristine arginfo_class_Memcached_resetServerList

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Memcached_checkKey, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
ZEND_END_ARG_INFO()

#if defined(HAVE_MEMCACHED_PROTOCOL)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_MemcachedServer_run, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, address, IS_STRING, 0)
Expand Down Expand Up @@ -325,6 +329,7 @@ ZEND_METHOD(Memcached, setEncodingKey);
#endif
ZEND_METHOD(Memcached, isPersistent);
ZEND_METHOD(Memcached, isPristine);
ZEND_METHOD(Memcached, checkKey);
#if defined(HAVE_MEMCACHED_PROTOCOL)
ZEND_METHOD(MemcachedServer, run);
#endif
Expand Down Expand Up @@ -396,6 +401,7 @@ static const zend_function_entry class_Memcached_methods[] = {
#endif
ZEND_ME(Memcached, isPersistent, arginfo_class_Memcached_isPersistent, ZEND_ACC_PUBLIC)
ZEND_ME(Memcached, isPristine, arginfo_class_Memcached_isPristine, ZEND_ACC_PUBLIC)
ZEND_ME(Memcached, checkKey, arginfo_class_Memcached_checkKey, ZEND_ACC_PUBLIC)
ZEND_FE_END
};

Expand Down
8 changes: 7 additions & 1 deletion php_memcached_legacy_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 573d35c5c6b6c397943e0f8ab9c505e2f4ce9e34 */
* Stub hash: 3f4694d4e1f3d1647a832acd8539b056b2ab5e7a */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Memcached___construct, 0, 0, 0)
ZEND_ARG_INFO(0, persistent_id)
Expand Down Expand Up @@ -245,6 +245,10 @@ ZEND_END_ARG_INFO()

#define arginfo_class_Memcached_isPristine arginfo_class_Memcached_getResultCode

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Memcached_checkKey, 0, 0, 1)
ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()

#if defined(HAVE_MEMCACHED_PROTOCOL)
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MemcachedServer_run, 0, 0, 1)
ZEND_ARG_INFO(0, address)
Expand Down Expand Up @@ -321,6 +325,7 @@ ZEND_METHOD(Memcached, setEncodingKey);
#endif
ZEND_METHOD(Memcached, isPersistent);
ZEND_METHOD(Memcached, isPristine);
ZEND_METHOD(Memcached, checkKey);
#if defined(HAVE_MEMCACHED_PROTOCOL)
ZEND_METHOD(MemcachedServer, run);
#endif
Expand Down Expand Up @@ -392,6 +397,7 @@ static const zend_function_entry class_Memcached_methods[] = {
#endif
ZEND_ME(Memcached, isPersistent, arginfo_class_Memcached_isPersistent, ZEND_ACC_PUBLIC)
ZEND_ME(Memcached, isPristine, arginfo_class_Memcached_isPristine, ZEND_ACC_PUBLIC)
ZEND_ME(Memcached, checkKey, arginfo_class_Memcached_checkKey, ZEND_ACC_PUBLIC)
ZEND_FE_END
};

Expand Down