Skip to content

Commit

Permalink
Merge pull request #1427 from sjinks/issue-1413
Browse files Browse the repository at this point in the history
Http\Cookie::__toString() should not throw exceptions
  • Loading branch information
Phalcon committed Oct 24, 2013
2 parents 4a81bb8 + 6840ca8 commit 46f6182
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
29 changes: 23 additions & 6 deletions ext/http/cookie.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,14 +851,31 @@ PHP_METHOD(Phalcon_Http_Cookie, __toString){

zval *value;

PHALCON_MM_GROW();

value = phalcon_fetch_nproperty_this(this_ptr, SL("_value"), PH_NOISY_CC);
if (Z_TYPE_P(value) == IS_NULL) {
phalcon_return_call_method_p0(this_ptr, "getvalue");
RETURN_MM();
if (FAILURE == phalcon_call_method_params(return_value, return_value_ptr, this_ptr, SL("getvalue"), zend_inline_hash_func(SS("getvalue")) TSRMLS_CC, 0)) {
if (EG(exception)) {
zval *e = EG(exception);
zval *m = zend_read_property(Z_OBJCE_P(e), e, SL("message"), 1 TSRMLS_CC);

Z_ADDREF_P(m);
if (Z_TYPE_P(m) != IS_STRING) {
convert_to_string_ex(&m);
}

if (return_value_ptr) {
ALLOC_INIT_ZVAL(*return_value_ptr);
}

zend_clear_exception(TSRMLS_C);
zend_error(E_ERROR, "%s", Z_STRVAL_P(m));
zval_ptr_dtor(&m);
}
}

convert_to_string(return_value_ptr ? *return_value_ptr : return_value);
return;
}

RETURN_CTOR(value);
RETURN_ZVAL(value, 1, 0);
}

13 changes: 13 additions & 0 deletions ext/tests/issue-1427.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Phalcon\Http\Cookie::toString() throws exceptions - https://github.com/phalcon/cphalcon/pull/1427
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php
$_COOKIE['name'] = 'value';
$c = new \Phalcon\Http\Cookie('name');
$c->useEncryption(true);
echo $c, PHP_EOL;
?>
--EXPECTF--
Fatal error: A dependency injection object is required to access the '%s' service in %s on line %d
11 changes: 11 additions & 0 deletions ext/tests/issue-1428.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
Phalcon\Http\Cookie::__toString() must return a string value - https://github.com/phalcon/cphalcon/issue/1428
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php
$c = new \Phalcon\Http\Cookie('name');
echo $c, PHP_EOL;
?>
--EXPECT--

0 comments on commit 46f6182

Please sign in to comment.