Skip to content

Commit

Permalink
Merge pull request laruence#1 from laruence/master
Browse files Browse the repository at this point in the history
merge with laruence
  • Loading branch information
wenjun1055 committed Mar 14, 2013
2 parents 4e3bc35 + 5695d31 commit 72c0093
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
11 changes: 4 additions & 7 deletions routes/yaf_route_regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ static zval * yaf_route_regex_match(yaf_route_t *route, char *uir, int len TSRML
if ((pce_regexp = pcre_get_compiled_regex_cache(Z_STRVAL_P(match), Z_STRLEN_P(match) TSRMLS_CC)) == NULL) {
return NULL;
} else {
zval *matches, *subparts, *map;
zval matches, *subparts, *map;

MAKE_STD_ZVAL(matches);
MAKE_STD_ZVAL(subparts);
ZVAL_NULL(subparts);

Expand All @@ -99,11 +98,10 @@ static zval * yaf_route_regex_match(yaf_route_t *route, char *uir, int len TSRML
map = NULL;
}

php_pcre_match_impl(pce_regexp, uir, len, matches, subparts /* subpats */,
php_pcre_match_impl(pce_regexp, uir, len, &matches, subparts /* subpats */,
0/* global */, 0/* ZEND_NUM_ARGS() >= 4 */, 0/*flags PREG_OFFSET_CAPTURE*/, 0/* start_offset */ TSRMLS_CC);

if (!Z_LVAL_P(matches)) {
zval_ptr_dtor(&matches);
if (!zend_hash_num_elements(Z_ARRVAL_P(subparts))) {
zval_ptr_dtor(&subparts);
return NULL;
} else {
Expand All @@ -126,7 +124,7 @@ static zval * yaf_route_regex_match(yaf_route_t *route, char *uir, int len TSRML
}

if (zend_hash_get_current_key_ex(ht, &key, &len, &idx, 0, NULL) == HASH_KEY_IS_LONG) {
if (map && zend_hash_index_find(Z_ARRVAL_P(map), idx, (void **)&name) == SUCCESS) {
if (map && zend_hash_index_find(Z_ARRVAL_P(map), idx, (void **)&name) == SUCCESS && Z_TYPE_PP(name) == IS_STRING) {
Z_ADDREF_P(*ppzval);
zend_hash_update(Z_ARRVAL_P(ret), Z_STRVAL_PP(name), Z_STRLEN_PP(name) + 1, (void **)ppzval, sizeof(zval *), NULL);
}
Expand All @@ -136,7 +134,6 @@ static zval * yaf_route_regex_match(yaf_route_t *route, char *uir, int len TSRML
}
}

zval_ptr_dtor(&matches);
zval_ptr_dtor(&subparts);
return ret;
}
Expand Down
10 changes: 3 additions & 7 deletions routes/yaf_route_rewrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,17 @@ static zval * yaf_route_rewrite_match(yaf_route_t *router, char *uir, int len TS
smart_str_free(&pattern);
return NULL;
} else {
zval *matches, *subparts;
zval matches, *subparts;

smart_str_free(&pattern);

MAKE_STD_ZVAL(matches);
MAKE_STD_ZVAL(subparts);
ZVAL_LONG(matches, 0);
ZVAL_NULL(subparts);

php_pcre_match_impl(pce_regexp, uir, len, matches, subparts /* subpats */,
php_pcre_match_impl(pce_regexp, uir, len, &matches, subparts /* subpats */,
0/* global */, 0/* ZEND_NUM_ARGS() >= 4 */, 0/*flags PREG_OFFSET_CAPTURE*/, 0/* start_offset */ TSRMLS_CC);

if (!Z_LVAL_P(matches)) {
zval_ptr_dtor(&matches);
if (!zend_hash_num_elements(Z_ARRVAL_P(subparts))) {
zval_ptr_dtor(&subparts);
return NULL;
} else {
Expand Down Expand Up @@ -172,7 +169,6 @@ static zval * yaf_route_rewrite_match(yaf_route_t *router, char *uir, int len TS
}
}

zval_ptr_dtor(&matches);
zval_ptr_dtor(&subparts);
return ret;
}
Expand Down
34 changes: 34 additions & 0 deletions tests/066.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
Check for Yaf_Route_Regex with abnormal map
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--FILE--
<?php
$request = new Yaf_Request_Http("/subdir/ap/1.2/xxx/name/value", "/subdir");

$router = new Yaf_Router();

$router->addRoute("ap", new Yaf_Route_Regex(
"#^/ap/([^/]*)/([^/]*)/*#i",
array(
"action" => 'ap',
),
array(
1 => 23432,
2 => NULL,
)
))->route($request);

var_dump($router->getCurrentRoute());
var_dump($request->getParam(1));
var_dump($request->getActionName());
var_dump($request->getControllerName());
var_dump($request->getParam('name'));

?>
--EXPECTF--
string(2) "ap"
NULL
string(2) "ap"
NULL
NULL
2 changes: 1 addition & 1 deletion yaf_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ PHP_METHOD(yaf_application, __construct) {
app = zend_read_static_property(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_APP), 1 TSRMLS_CC);

#if PHP_YAF_DEBUG
php_error_docref(NULL, E_STRICT, "Yaf is running in debug mode");
php_error_docref(NULL TSRMLS_CC, E_STRICT, "Yaf is running in debug mode");
#endif

if (!ZVAL_IS_NULL(app)) {
Expand Down
4 changes: 4 additions & 0 deletions yaf_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,19 +393,23 @@ PHP_METHOD(yaf_controller, forward) {
}

request = zend_read_property(yaf_controller_ce, self, ZEND_STRL(YAF_CONTROLLER_PROPERTY_NAME_REQUEST), 1 TSRMLS_CC);
#if 0
parameters = zend_read_property(yaf_controller_ce, self, ZEND_STRL(YAF_CONTROLLER_PROPERTY_NAME_ARGS), 1 TSRMLS_CC);
#endif

if (Z_TYPE_P(request) != IS_OBJECT
|| !instanceof_function((request_ce = Z_OBJCE_P(request)), yaf_request_ce TSRMLS_CC)) {
RETURN_FALSE;
}

#if 0
if (ZVAL_IS_NULL(parameters)) {
MAKE_STD_ZVAL(parameters);
array_init(parameters);
zend_update_property(yaf_controller_ce, self, ZEND_STRL(YAF_CONTROLLER_PROPERTY_NAME_ARGS), parameters TSRMLS_CC);
zval_ptr_dtor(&parameters);
}
#endif

switch (ZEND_NUM_ARGS()) {
case 1:
Expand Down

0 comments on commit 72c0093

Please sign in to comment.