Skip to content

Commit

Permalink
Merge pull request #1613 from sjinks/1.2.5
Browse files Browse the repository at this point in the history
[1.2.5] Backport #1575 from 1.3.0
  • Loading branch information
Phalcon committed Nov 28, 2013
2 parents b70f24e + 1a1abe1 commit 6594974
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 6 deletions.
26 changes: 21 additions & 5 deletions ext/flash/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ PHP_METHOD(Phalcon_Flash_Session, message){
PHP_METHOD(Phalcon_Flash_Session, getMessages){

zval *type = NULL, *remove = NULL, *messages, *return_messages;
zval *do_remove;

PHALCON_MM_GROW();

Expand All @@ -221,15 +222,30 @@ PHP_METHOD(Phalcon_Flash_Session, getMessages){
PHALCON_INIT_VAR(remove);
ZVAL_BOOL(remove, 1);
}


if (Z_TYPE_P(type) != IS_NULL) {
PHALCON_INIT_VAR(do_remove);
ZVAL_FALSE(do_remove);
}
else {
do_remove = remove;
}

PHALCON_INIT_VAR(messages);
phalcon_call_method_p1(messages, this_ptr, "_getsessionmessages", remove);
if (Z_TYPE_P(messages) == IS_ARRAY) {
if (likely(Z_TYPE_P(type) == IS_STRING)) {
phalcon_call_method_p1(messages, this_ptr, "_getsessionmessages", do_remove);
if (Z_TYPE_P(messages) == IS_ARRAY) {
if (likely(Z_TYPE_P(type) != IS_NULL)) {
if (phalcon_array_isset(messages, type)) {
PHALCON_OBS_VAR(return_messages);
phalcon_array_fetch(&return_messages, messages, type, PH_NOISY);
RETURN_CCTOR(return_messages);
RETVAL_ZVAL(return_messages, 1, 0);
if (zend_is_true(remove)) {
phalcon_array_unset(&messages, type, 0);
phalcon_call_method_p1_noret(this_ptr, "_setsessionmessages", messages);
}

PHALCON_MM_RESTORE();
return;
}

RETURN_MM_EMPTY_ARRAY();
Expand Down
7 changes: 6 additions & 1 deletion ext/tests/issue-1340-valgrind.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
--TEST--
Memory corruption in zim_Phalcon_Security_hash() - https://github.com/phalcon/cphalcon/issues/1340 - run under Valgrind!
--SKIPIF--
<?php include('skipif.inc'); ?>
<?php
include('skipif.inc');
if (!extension_loaded('openssl')) {
die('skip OpenSSL extension is not loaded');
}
?>
--FILE--
<?php
$s = new \Phalcon\Security();
Expand Down
43 changes: 43 additions & 0 deletions ext/tests/issue-1575.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--TEST--
flashSession->getMessages(type, BOOLEAN remove) removed all messages - https://github.com/phalcon/cphalcon/issues/1575
--GET--
dummy=1
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php
$di = new \Phalcon\DI\FactoryDefault();
$s = new \Phalcon\Session\Adapter\Files(array('uniqueId' => 'issue-1575'));
var_dump($s->start());
$fs = $di->getShared('flashSession');
$fs->success('Success');
$fs->warning('Warning');
var_dump($fs->getMessages(null, false));
$fs->getMessages('success', true);
var_dump($fs->getMessages(null, false));
$fs->getMessages(null, true);
var_dump($fs->getMessages(null, false));
?>
--EXPECT--
bool(true)
array(2) {
["success"]=>
array(1) {
[0]=>
string(7) "Success"
}
["warning"]=>
array(1) {
[0]=>
string(7) "Warning"
}
}
array(1) {
["warning"]=>
array(1) {
[0]=>
string(7) "Warning"
}
}
array(0) {
}

0 comments on commit 6594974

Please sign in to comment.