minkphp / MinkBrowserKitDriver

Symfony2 BrowserKit driver for Mink framework
MIT License
549 stars 80 forks source link

Delete cookie in subpath correctly #157

Closed andrewnicols closed 3 years ago

andrewnicols commented 3 years ago

The getCookiePath() function was assuming that the full path name of the current URL includes the full filename - for example /sub-folder/index.php.

However, where the browser visits the parent folder and the default file is served (/sub-folder/ serving /sub-folder/index.php) the wrong current URL is returned.

This means that the deleteCookie function tries to delete for the parent folder upwards, and where the cookie was set in a specific path, the delete fails.

For example:

Given a cookie set with:

setcookie('somename', 'somevalue', 0, '/some/sub-folder/');

The following would fail:

$session->visit('/some/sub-folder/');
$session->setCookie('somename', null);

The setCookie call would call deleteCookie, which fetches the URL to delete. The getCookiePath() function would behaved such that:

$path = dirname(parse_url($this->getCurrentUrl(), PHP_URL_PATH));
$path = dirname('/some/sub-folder/');
$path = '/some/';

Then, when fetching and expiring the cookie on the jar, the path of /some/ was used to try and find a cookie located at /some/sub-folder/.

As a result the call to both get and expire the cookie from the jar would fail as the path was never exact enough.

andrewnicols commented 3 years ago

Pull request raised to add a new test for this issue in https://github.com/minkphp/driver-testsuite/pull/47

aik099 commented 3 years ago

Merging, thank you @andrewnicols .