Skip to content

Commit

Permalink
Fix more tests with a slight refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rlerdorf authored and m6w6 committed Sep 26, 2024
1 parent 198e9b3 commit da71ae0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions php_memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,9 @@ zend_bool s_memc_valid_key_ascii(zend_string *key)
#define MEMC_CHECK_KEY(intern, key) \
if (UNEXPECTED(ZSTR_LEN(key) == 0 || \
ZSTR_LEN(key) > MEMC_OBJECT_KEY_MAX_LENGTH || \
memcached_behavior_get(intern->memc, MEMCACHED_BEHAVIOR_VERIFY_KEY) && \
(memcached_behavior_get(intern->memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) \
? !s_memc_valid_key_binary(key) \
: !s_memc_valid_key_ascii(key) \
: (memcached_behavior_get(intern->memc, MEMCACHED_BEHAVIOR_VERIFY_KEY) && !s_memc_valid_key_ascii(key)) \
))) { \
intern->rescode = MEMCACHED_BAD_KEY_PROVIDED; \
RETURN_FALSE; \
Expand Down
5 changes: 4 additions & 1 deletion tests/get.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ Memcached::get()
--FILE--
<?php
include dirname(__FILE__) . '/config.inc';
$m = memc_get_instance ();
$m = memc_get_instance (array (
Memcached::OPT_BINARY_PROTOCOL => false,
Memcached::OPT_VERIFY_KEY => true
));

$m->delete('foo');

Expand Down
5 changes: 1 addition & 4 deletions tests/keys_ascii.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ Test valid and invalid keys - ascii
include dirname (__FILE__) . '/config.inc';
$ascii = memc_get_instance (array (
Memcached::OPT_BINARY_PROTOCOL => false,
Memcached::OPT_VERIFY_KEY => false
Memcached::OPT_VERIFY_KEY => true
));
// libmemcached can verify keys, but these are tests are for our own
// function s_memc_valid_key_ascii, so explicitly disable the checks
// that libmemcached can perform.

echo 'ASCII: SPACES' . PHP_EOL;
var_dump ($ascii->set ('ascii key with spaces', 'this is a test'));
Expand Down

0 comments on commit da71ae0

Please sign in to comment.