Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phalcon\Session\Bag: add of initialization for remove() #12647

Closed
wants to merge 1 commit into from

Conversation

morafabio
Copy link
Contributor

@morafabio morafabio commented Feb 22, 2017

  • Type: bug fix
  • Issue: when Phalcon\Session\Bag is restored by the session handler, the _data property results not initialized and remove() won't work properly.

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the Contributing Guidelines?
  • I have checked that another pull request for this purpose does not exist.
  • I wrote some tests for this PR.

Small description of change: Initialization steps in remove() have been added.

Steps to reproduce:

// debug with reflection
$reflectionClass = new \ReflectionClass(get_class($this->bag));
$_data = $reflectionClass->getProperty('_data');
$_data->setAccessible(true);
$_initialized = $reflectionClass->getProperty('_initialized');
$_initialized->setAccessible(true);

// create a Bag with one value
$bag = new \Phalcon\Session\Bag('fruit');
$bag->set('apples', 10);
var_dump($bag->get('apples')); // int(10)
var_dump($_data->getValue($bag)); // array(1) { ["apples"]=> int(10) }
var_dump($_initialized->getValue($bag)); // bool(true)

// save and cleanup
$serializedBag = serialize($bag);
unset($bag);

// emulate restore in the same way it would be done
// any PHP session handler, e.g.: `session.save_handler => redis => redis`
$bag = unserialize($serializedBag);
$_data->setValue($bag, NULL);
$_initialized->setValue($bag, false);

// remove attempt fails because `_data` is NULL
var_dump($bag->remove('apples')); // bool(false) // EXPECTED: bool(true)
var_dump($bag->get('apples')); // int(10) // EXPECTED: NULL

// get performs _initialize under the hood, so now it works
var_dump($bag->remove('apples')); // bool(true)
var_dump($bag->get('apples')); // NULL

this calls initialize also on Bag::remove.

Run tests: vagrant@phalcon:~/cphalcon$ vendor/bin/codecept run tests/unit/Session/BagTest

Thanks

CHANGELOG.md Outdated
@@ -1,3 +1,5 @@
- Fixed `Phalcon\Session\Bag::remove` to initialize the bag before removing a value

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add this to bottom of the [3.1.0] section?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@morafabio morafabio force-pushed the 3.1.x-bag-remove-bug branch from 83d6aa6 to 9bbcb17 Compare February 22, 2017 10:55
@morafabio
Copy link
Contributor Author

morafabio commented Feb 22, 2017

@sergeyklay ManagerTest|ModelTest looks failing but I have no idea on how this is related to my change. Any hint :)?

@morafabio
Copy link
Contributor Author

morafabio commented Feb 22, 2017

Hum... Looks the the build of 3.1.0 was already failing: https://travis-ci.org/phalcon/cphalcon/jobs/203022574

@sergeyklay
Copy link
Contributor

sergeyklay commented Feb 22, 2017

Will be fixed after #12644

@morafabio
Copy link
Contributor Author

Ok, so do you need me to fix something other?

@sergeyklay
Copy link
Contributor

I'll take a look later. Thank you for contributing.

@morafabio
Copy link
Contributor Author

👍

@sergeyklay
Copy link
Contributor

Thank you. Merged to the 3.1.x

@sergeyklay sergeyklay closed this Feb 25, 2017
@morafabio morafabio deleted the 3.1.x-bag-remove-bug branch February 27, 2017 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants